Use JavaScript to verify the regular expression of the mobile phone number

Source: Internet
Author: User

Use JavaScript to verify the regular expression of the mobile phone number. The Code is as follows:

Function checkMobile () {var phone = document. getElementById ("phone"). value; var reg0 =/^ 13 \ d {5, 9} $/; // 130--139. At least 7-bit var reg1 =/^ 153 \ d {8} $/; // China Unicom 153. At least 7 bits var reg2 =/^ 159 \ d {8} $/; // move 159. At least 7-bit var reg3 =/^ 158 \ d {8} $/; var reg4 =/^ 150 \ d {8} $/; var my = false; if (reg0.test (phone) {my = true;} if (reg1.test (phone) {my = true;} if (reg2.test (phone) {my = true ;} if (reg3.test (phone) {my = true;} if (reg4.test (phone) {my = true;} if (! My) {alert ('Sorry, the phone number you entered is incorrect. ')} Else {alert ("congratulations, the entered mobile phone number is correct ");}}
Articles you may be interested in
  • Example of mobile phone number and email address verification in js
  • Js verification mobile phone number function (from Ding ding map)
  • Summary of common Regular Expressions
  • How to Write efficient regular expressions
  • Sort regular expressions that are frequently used
  • PHP function for verifying that the ID card number is correct
  • PHP Regular Expressions (2)
  • PHP Regular Expressions (1)

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.