Skip to content


更新个php验证email正则

网上随处可见的验证规则会漏掉用户名中常见字符”.”,”-“,”_”;
以及后缀中可能是二级或三级域名的情况.

‘*’ ‘+’ 和 ‘?’的规则
‘*’ 匹配0或多次
‘+’ 匹配1或多次
‘?’ 匹配0或1次

下面函数的验证规则为:
必需有一个不以”.”开头的字符后接0到多个字符
接上@须有一个字符开头接上0到多个包含”.”的子域名
最后接上”.”开头2到4个字符的域名后缀


function validEmail($address)
{
if(!preg_match(“/^[0-9a-zA-Z_-]+(\.[0-9a-zA-Z_-]+)*@[a-zA-Z0-9_-]+(\.{1}[a-zA-Z0-9_-]+)*\.{1}[a-zA-Z]{2,4}$/i”,$address))
{
return False;
}
return True;
}

Posted in PHP.

Tagged with , , .


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. dresses says

    C#上不能使用这个,我最近研究C#实现一些功能关于图象处理。



Some HTML is OK

or, reply to this post via trackback.