This article mainly describes how to verify the validity of mobile phone numbers and phone numbers by js Code. Mobile phone numbers and phone numbers are mandatory on some websites. To improve user experience, this document describes how to verify the validity of mobile phone numbers and phone numbers by using JavaScript code, mobile phone numbers and phone numbers are mandatory on some websites. To improve user experience, the legality verification is generally required. The Code is as follows:
Function Checkreg (){.....
Function Checkreg () {// verify the mobile phone number of the phone number, including, number segment if (document. form. phone. value = "" & document. form. userMobile. value = "") {alert ("either phone number or mobile phone number is required! "); Document. form. phone. focus (); return false;} if (document. form. phone. value! = "") {Var phone = document. form. phone. value; var p =/^ ([\ +] \ d {,}-)? (\ D {,})-)? (\ D {,}) (-(\ d {,}))? $/; Var me = false; if (p. test (phone) {me = true;} if (! Me) {document. form. phone. value = ''; alert ('Sorry, the phone number you entered is incorrect. Use-to separate the area code from the phone number); document. form. phone. focus (); return false ;}} if (document. form. UserMobile. value! = "") {Var mobile = document. form. userMobile. value; var reg =/^ \ d {, }$/; var reg =/^ \ d {, }$/; var reg =/^ \ d {,} $/; var reg =/^ \ d {,} $/; var my = false; if (reg. test (mobile) my = true; if (reg. test (mobile) my = true; if (reg. test (mobile) my = true; if (reg. test (mobile) my = true; if (! My) {document. form. UserMobile. value = ''; alert ('Sorry, the phone number or PHS number you entered is incorrect. '); Document. form. UserMobile. focus (); return false ;}return true ;}}
The above code is to use js to verify whether the mobile phone number and phone number are legal. I hope you will like it.