Here are some of the simplest telephone number verification, which only determines that the user entered the data can be passed this is very problematic
The code is as follows |
Copy Code |
function Number_validator (TestValue) { var Checkok = "0123456789"; var checkstr = TestValue; var allvalid = true; for (i = 0; i < checkstr.length; i++) { ch = checkstr.charat (i); for (j = 0; J < Checkok.length; J + +) if (ch = = Checkok.charat (j)) Break if (j = = Checkok.length) { return (false); } } return (true); } |
such as user input 123456789 is this the phone, then we look at another call to verify the code
Because the method is the same, just write the relevant regular expression
For mobile phone number verification (provided in two ways)
var mobile=/^ ((13[0-9]{1}) |159|153) +d{8}$/;
var mobile1=/^ (13+d{9}) | (159+d{8}) | (153+d{8}) $/;
Verify the mobile phone number (check the 13,15,18 of the beginning of the phone number!) )
code is as follows |
copy code |
function Check_telephone (obj) { var reg=/^[1][358]d{9}$/; & nbsp; if (obj.value!= "&&!reg.test (obj.value)) { alert (' Phone number format input Error! '); obj.value = ""; obj.focus (); return false; } } |
//Validation for area code
var phoneareanum =/^d{3,4}$/
//Authentication for phone number
var phone =/^d{7,8}$/;
code is as follows |
copy code |
function check _phone (obj) { var reg=/^ ([0+]d{2,3}-)? 0d{2,3})? (d{7,8}) (-(D{3,})?$/; if (obj.value!= "" &&!reg.test (obj.value)) { alert (' Phone number format input Error! '); obj.value = ""; obj.focus (); return false; } } |
Verifying fixed Phone numbers
0d{2,3} represents the area code
[0+]d{2,3} represents the international area code
d{7,8} represents 7-8 digits (for phone numbers)
Correct format: Area code-Phone number-extension number (all write | write phone number only)
Call method We just add onsubmit= ' return to the form (Checkinput (this)) '