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)