The JS regular code that verifies the phone number

Source: Internet
Author: User

/^d{3,4}-d{7,8} (-d{3,4})? The $/area code must be filled with a 3-4-digit number, followed by "-" to connect to the phone number

^d{3,4}-number with 7-8 digits

d{7,8} extension number is 3-4 digits, not required, but if filled with "-" and telephone number to connect

(-d{3,4})? cell phone number Regular expression
Verify the mobile phone number, ignore the front 0, support 130-139,150-159. Ignore the front 0 and judge it to be 11-bit.

The regular of the Cloeft:

/^0* (13|15) d{9}$/^0* matches any number of the initial 0.

Because the mobile phone number is 13 any number 9 bits, and 15 any number 9 bits, so can use (13|15) d{9} match.

The test code is as follows:

  code is as follows copy code

  function Testreg (reg,str) {
  return reg.test (str);
 }
 var reg =/^0* (13|15) d{9}$/;
 var str = ' 13889294444 ';
 var str2 = ' 12889293333 ';
 var str3 = ' 23445567 ';
 document.write (Testreg (reg,str) + ' <br/> ');
 document.write (Testreg (REG,STR2) + ' <br/> ');
 document.write (Testreg (REG,STR3) + ' <br/> ');

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.