主页 M

php使用正则验证邮箱

2015-03-27 网页编程网 网页编程网
<?php
/**
* 邮箱地址正则表达式
*/
$preg = '/^(\w{1,25})@(\w{1,16})(\.(\w{1,4})){1,3}$/';
$b = 'ffgddayasdadasdf@gmialsdfsdfasd3.com.cn.org';
if(preg_match($preg, $b)){
echo "匹配到了";
}else{
echo "没有匹配到";
}

//邮箱正则验证 示例2
if (ereg(“/^[a-z]([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?$/i; ”,$email)){ 
   echo “Your email address is correct!”;} 
else{ 
   echo “Please try again!”; 
} 

//邮箱正则验证 示例3
function checkEmail($email)
{
    $pregEmail = "/([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i";
    return preg_match($pregEmail,$email);  
}
?>
阅读原文
阅读 3794
123 显示电脑版