In PHP, we often use regular expressions to verify whether the information entered by the user is an email address. Let me introduce to you a detailed explanation of the regular expression to determine the email address.
A regular expression to determine the email address. , explain what it means sentence by sentence
The code is as follows
代码如下 |
复制代码 |
^(w+((-w+)|(.w+))*)+w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$
|
|
Copy code
|
^(w+((-w+)|(.w+))*)+w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-) [A-Za-z0-9]+)*.[A-Za-z0-9]+$
^ Match string header
(w+((-w+)|(.w+))*) 1: This matches strings such as laidfj456, sfi-lsoke, fe.23i
+ Matches the plus sign
w+((-w+)|(.w+))* Same as 1
@ Match@
[A-Za-z0-9]+ 2: A string consisting of uppercase and lowercase letters and numbers, equivalent to w+
((.|-)[A-Za-z0-9]+)* Matches 0 or more strings starting with "." or "-", such as .oeiu234mJ, -oiwuer4
. Matches "."
代码如下 |
复制代码 |
/**
* 邮件的正则表达式 @author:lijianghai
*/
function isEmail($input = null)
{ //用户名:以数字、字母、下滑线组成;
$email = $input;
/*使用preg_ereg()出错:因为第二个参数需要是数组
* if(preg_grep("^[a-zA-Z][a-zA-Z0-9_]{3,19}@[0-9A-Za-z]{1,10}(.)(com|cn|net|com.cn)$", array($input)))
{
echo $email.'是符合条件的邮件地址';
}else
{
echo $email.'格式错误';
}
*/
if(ereg("^[a-zA-Z][a-zA-Z0-9_]{3,9}@[0-9a-zA-Z]{1,10}(.)(com|cn|com.cn|net)$",$email))
{
echo $email."符合格式规范";
}
else
{
echo $email.'格式错误';
}
}
$email = "";
isEmail($email);
?>
|
| [A-Za-z0-9]+ Same as 2
$ Matches the ? tail of the string
Example
The code is as follows
|
Copy code
/**
* Regular expression for emails @author:lijianghai
*/
function isEmail($input = null)
{ //Username: composed of numbers, letters, and underscores;
$email = $input;
/*Error using preg_ereg(): because the second parameter needs to be an array
* if(preg_grep("^[a-zA-Z][a-zA-Z0-9_]{3,19}@[0-9A-Za-z]{1,10}(.)(com|cn |net|com.cn)$", array($input)))
{
echo $email.'is a qualified email address';
}else
echo $email.'Format error';<🎜>
}<🎜>
*/<🎜>
if(ereg("^[a-zA-Z][a-zA-Z0-9_]{3,9}@[0-9a-zA-Z]{1,10}(.)(com|cn| com.cn|net)$",$email))<🎜>
{<🎜>
echo $email."Conforms to format specifications";<🎜>
}<🎜>
else<🎜>
{<🎜>
echo $email.'Format error';<🎜>
}<🎜>
}<🎜>
$email = "";<🎜>
isEmail($email);<🎜>
?>
http://www.bkjia.com/PHPjc/631271.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631271.htmlTechArticleIn php, we often use regular expressions to verify whether the information entered by the user is an email address, as follows Let me introduce to you the regular expression to determine the email address in detail...
|
|
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