How php verifies mobile phone numbers

Source: Internet
Author: User
Tags php regular expression
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.