Heim  >  Artikel  >  Backend-Entwicklung  >  PHP 正则表达式问题

PHP 正则表达式问题

WBOY
WBOYOriginal
2016-06-06 20:36:51906Durchsuche

  1. test@baidu.com
  2. test@baidu.com.cn
  3. test@baidu.a.com.cn

要用PHP正则判断是否合法的邮箱名称?

回复内容:

  1. test@baidu.com
  2. test@baidu.com.cn
  3. test@baidu.a.com.cn

要用PHP正则判断是否合法的邮箱名称?

php5.2版本的内置函数基本可以完美解决邮箱验证。
filter_var('bob@example.com', FILTER_VALIDATE_EMAIL);

呵呵,骚年,以为那么短的正则就能验证所有可能出现的邮箱格式吗!

最完备的Email地址正则表达式,长达6318个字符。

PHP 正则表达式问题

这个google一下就出来了吧

\w+([-+.]\w+)@\w+([-.]\w+).\w+([-.]\w+)*

针对php验证邮箱是否合法的问题,我个人建议可以参考PHPMailer的验证方式(class.phpmailer.php的validateAddress方法。)

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn