We used php regular expression to verify mobile phone numbers. The rule for mobile phone numbers is to have 11 characters and start with "13, 15, 18, in this case, we only need to classify and plan and implement the perfect mobile phone number verification regular expression. Everyone should have this common sense: Chinese mobile phone number... we used php regular expression to verify mobile phone numbers. The rule for mobile phone numbers is to have 11 characters and start with "13, 15, 18, in this case, we only need to classify and plan and implement the perfect mobile phone number verification regular expression.
Everyone should have this knowledge. Chinese mobile phone numbers all start with numbers "1", and then use "0 ~ 9 "11 digits in 10 digits
Number combination, then our verification rules must be written according to this idea.
Based on the simple idea above, we can write the following verification code:
But the above code is obviously not rigorous enough, because in this way, even if the mobile phone number "18888888888" can pass verification, because
We also need to perform more rigorous verification on the mobile phone number. before the strict verification, please let us first see that the first three common mobile phone numbers in China all have
Some:
Mobile phone number: 134, 135, 136, 137, 138, 139, 150, 151, 157, 158 (TD), 159, 187, 188
China Unicom mobile phone number: 130, 131, 132, 152, 155, 156, 185, 186
China Telecom mobile phone number: 133, 153, 180, 189, (1349 Weitong)
Then, based on the above features, we can modify the code into such a rule:
It can only start with. if a new segment does not work, we can modify it.
function is_mobile($str){ return preg_match("/^(((d{3}))|(d{3}-))?13d{9}$/", $str); }
In this way, all the mobile phone numbers can be verified.
Permanent link:
Reprint at will! Include the article address.