PHP Regular method of judging mobile phone number

Source: Internet
Author: User

When using regular matching mobile phone number, we first analyze the law of mobile phone number:

1. Mobile phone number is usually 11-bit

2. Often the beginning of 1

3. The second figure is usually 34578 of these figures, the mobile phone number for the 170th segment of 2014.5.5 is on sale so there is a 7 more.

PHP uses regular expressions to determine how a mobile phone number is written:
  1. $g = "/^1[34578]\d{9}$/";
    The "^" symbol indicates that the 1 must be the beginning; "[]" means that the second digit must be a number in brackets; The \d represents 0-9 arbitrary numbers, followed by {9}, which indicates a length of 9 digits; The following $ represents the end; The start and end/regular expressions must be placed in the middle, and some may also follow the pattern.
This can be written by matching all the phone numbers in the article:
  1. $str = ' Old Bar blog author's cell phone is 18912345678 ';
  2. Preg_match_all ("/^1[34578]\d{9}$/", $str, $mobiles);
  3. Var_dump ($mobiles);
If you want to check whether the phone number entered by the user is correct, you can check this:
    1. if (Preg_match ("/^1[34578]\d{9}$/", $mobile)) {
    2. There's an infinite imagination here.
    3. }

PHP Regular method of judging mobile phone number

Related Article

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.