The code is as follows
Function funcMtel($str)//Mobile phone number regular expression test
{
Return (preg_match("/(?:13d{1}|15[03689])d{8}$/",$str))?true:false;
}
Test
18678785887
Return to
false
Cause analysis, after checking it, I found that the above regular expression can only verify those starting with 13,15, naturally those starting with 18 cannot be used
After modification
The code is as follows
Function funcMtel($str)//Mobile phone number regular expression test
{
return (preg_match("/(?:1[3|4|5|8]d{1}|15[03689])d{8}$/",$str))?true:false;
}
Test
18678785887
Return to
true
This will be successful,
Summary of experience:
Number segments such as mobile phone numbers will be constantly updated. When we write the function, we write it as a public function, so that we can solve this problem.