This article mainly introduces the JS code to verify the phone number and phone number is legitimate, mobile phone number and phone number in some sites are required, in order to improve the user experience, the general to verify the legality, the specific code is as follows:function Checkreg () { .....
function Checkreg () {//Verify phone number, contains, number segment if (document.form.phone.value== "" &&document.form.usermobile.value= = "") {alert ("Phone and mobile number at least one entry!")
");
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 wrong.
Please use-split ' between area code and telephone 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, you have entered the phone or PHS number is wrong.
');Document.form.UserMobile.focus ();
return false;
return true;
}
}
The above code is to use JS to verify the mobile phone number and phone number is legitimate full content, I hope you like.