Home  >  Article  >  Backend Development  >  Regular expression code for php email verification

Regular expression code for php email verification

WBOY
WBOYOriginal
2016-07-25 08:58:171089browse
This article introduces the regular expression for email verification in PHP. Friends in need can refer to it.

The regular expression for php email verification is as follows:

<?php
/**
* 邮箱地址正则表达式
* edit bbs.it-home.org
*/
$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);  
}
?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn