Mobile phone number and phone number legality verification code:
In some website phone number and mobile phone number are required, or need to fill in one of them, in order to enhance the authenticity of the site also improve the user experience, generally need to do format validation, the following is an excerpt from the network of a validation code for your reference, hoping to bring a certain help to everyone.
The code is as follows:
functionCheckreg () {//Verify the phone number of the phone number, including paragraph 153,159 if(document.form.phone.value== "" &&document.form.usermobile.value== "") {alert ("Choose at least one of the phone and mobile numbers!" "); Document.form.phone.focus (); return false; } if(Document.form.phone.value! = ""){ varPhone=Document.form.phone.value; varp1=/^ ([0\+]\d{2,3}-)? ( 0\d{2,3})? (\d{7,8}) (-(\d{3,}))? $/; varMe=false; if(P1.test (phone)) {Me=true; } if(!me) {Document.form.phone.value= ' '; Alert (' Sorry, the phone number you entered has an error. Between the area code and the phone number, use-split '); Document.form.phone.focus (); return false; } } if(Document.form.UserMobile.value! = ""){ varmobile=Document.form.UserMobile.value; varreg0=/^13\d{5,9}$/; varreg1=/^153\d{4,8}$/; varreg2=/^159\d{4,8}$/; varreg3=/^0\d{10,11}$/; varmy=false; if(Reg0.test (MOBILE)) my=true; if(Reg1.test (MOBILE)) my=true; if(Reg2.test (MOBILE)) my=true; if(Reg3.test (MOBILE)) my=true; if(!my) {Document.form.UserMobile.value= ' '; Alert (' Sorry, the phone or PHS number you entered is wrong. ‘); Document.form.UserMobile.focus (); return false; } return true; } }
The above code can achieve the validity of the phone number and mobile phone number format validation.
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8394
For more information, refer to: http://www.softwhy.com/javascript/
Mobile phone number and phone number legality verification code