php 邮箱验证函数

 1 function checkEmail($email) 
 2 {
 3    // Create the syntactical validation regular expression
 4    $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
 5  
 6    // Presume that the email is invalid
 7    $valid = 0;
 8  
 9    // Validate the syntax 字符串比对解析,与大小写无关。
10    if (eregi($regexp, $email))
11    {
12       list($username,$domaintld) = split("@",$email);
13       // Validate the domain
14       if (getmxrr($domaintld,$mxrecords))
15          $valid = 1;
16    } else {
17       $valid = 0;
18    }
19  
20    return $valid;
21  
22 }

 

posted @ 2016-08-12 15:14  沙瑞金书记  阅读(246)  评论(0编辑  收藏  举报