JS mobile phone number simple regular check

Source: Internet
Author: User

The number of mobile phone numbers is now in the following categories, including the new Three (166,199,198) issued in 17.

In some projects registered login or other, involving mobile phone number for a simple validation, in front of a simple test;

Determine if a string matches a cell phone number format
Mobile Number segment: 134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188,198
China Unicom: 130,131,132,145,155,156,166,170,171,175,176,185,186
Electrical Signal Segment: 133,149,153,170,173,177,180,181,189,199



The code is as follows:

1  functionphoneverify (str) {2 3              varReg =/^ ((13\d) | ( 14[5,7,9]) | (15[0-3,5-9]) | (166) | (17[0,1,3,5,7,8]) | (18[0-9]) | (19[8,9])) \d{8}/;4              5              if(Reg.test (str)) {6              return  true;7}Else{8                  return false;9              }Ten}

Knock on the blackboard!!

   var reg =/^ ((13\d) | ( 14[5,7,9]) | (15[0-3,5-9]) | (166) | (17[0,1,3,5,7,8]) | (18[0-9]) | (19[8,9])) \d{8}/;

Over here:

    1. ^: Represents the Beginning
    2. : The portion of the red box represents the first three-bit field of the matched cell phone number, for example (14[5,6,7]) that matches the 145/146/147 segment;[0-9] and \d represent the same meaning that matches a numeric character
    3. This means matching a numeric character, looping 8 times

As for some other verification to be more ...

If there is anything wrong, please leave a message and make progress together.

respect for the original: reprint please enclose the source https://www.cnblogs.com/lshdashi/p/9431850.html

JS mobile phone number simple regular check

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.