The simplest and most practical PHP mobile phone number regular expression, friends in need can refer to it.
Mobile: 134, 135, 136, 137, 138, 139, 150, 151, 157(TD), 158, 159, 187, 188
China Unicom: 130, 131, 132, 152, 155, 156, 185, 186
Telecom: 133, 153, 180, 189, (1349 Satcom)
Mobile phone number rules
The code is as follows
代码如下 |
复制代码 |
$regex = "/13[0-9]{9}|15[0|1|2|3|5|6|7|8|9]d{8}|18[0|5|6|7|8|9]d{8}/";
|
|
Copy code
|
$regex = "/13[0-9]{9}|15[0|1|2|3|5|6|7|8|9]d{8}|18[0|5|6 |7|8|9]d{8}/";
代码如下 |
复制代码 |
function is_mobile($str){
return preg_match(“/^(((d{3}))|(d{3}-))?13d{9}$/“, $str);
}
|
代码如下 |
复制代码 |
function checkMobile($str)
{
$pattern = “/^(13|15)d{9}$/”;
if (preg_match($pattern,$str))
{
Return true;
}
else
{
Return false;
}
}
//调用函数
$str = checkMobile(“15800000001″);
if($str)
{
echo(“符合手机号码标准”);
}
else
{
echo(“不符合手机号码标准”);
}
?>
|
Example 1
Judge mobile phone number:
The code is as follows
代码如下 |
复制代码 |
preg_match_all($regex,$row['mobile'], $phones);
if($phones){
正确
}
|
|
Copy code
|
| function is_mobile($str){
return preg_match(“/^(((d{3}))|(d{3}-))?13d{9}$/“, $str);
}
Example
The code is as follows
|
Copy code
|
function checkMobile($str)
{
$pattern = “/^(13|15)d{9}$/”;
If (preg_match($pattern,$str))
{
Return true;
}
{ <🎜>
Return false; <🎜>
} <🎜>
} <🎜>
//Call function <🎜>
$str = checkMobile(“15800000001″); <🎜>
if($str) <🎜>
{ <🎜>
echo("Conforms to mobile phone number standards"); <🎜>
} <🎜>
else <🎜>
{ <🎜>
echo("Does not meet mobile phone number standards"); <🎜>
} <🎜>
?>
Finally, you can completely verify all current mobile phone number codes
The code is as follows
|
Copy code
|
preg_match_all($regex,$row['mobile'], $phones);
if($phones){
Correct
}
Friendly reminder, it is really not easy to judge the mobile phone number now, because the mobile phone number has changed a lot. Maybe you wrote the regular rule today and a new number segment will be released tomorrow. Make a mobile phone number segment. For arrays, determine whether it is within the number segment. Array=array(130,131,132...)in_array(substr(number,0,3),array)
http://www.bkjia.com/PHPjc/628966.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628966.htmlTechArticleThe simplest and most practical PHP mobile phone number regular expression, friends in need can refer to it. Mobile: 134, 135, 136, 137, 138, 139, 150, 151, 157(TD), 158, 159, 187, 18...
|
|
|