Below provides two commonly used authentication fixed telephone number instance in the development, may verify the handset number and the telephone number, simultaneously verifies the fixed telephone number 0d{2,3} to represent the area code [0+]d{2,3} to represent the international area code d{7,8} represents 7-8 digits (to represent the telephone number).
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)
*/
Verify the mobile phone number (check the 13,15,18 of the beginning of the phone number!) )
function Check_telephone (obj) {
var reg=/^[1][358]d{9}$/;
if (obj.value!= "" &&!reg.test (Obj.value)) {
Alert (' Mobile number format input Error! ');
Obj.value = "";
Obj.focus ();
return false;
}
}
JS Test function
Definitions and usage
The test () method is used to detect whether a string matches a pattern.
Grammar
Regexpobject.test (String) parameter description
String required. The string to be instrumented.
return value
Returns True if string strings contain text that matches regexpobject, or false.
Description
Call the test () method of the RegExp object R and pass the string s to it, which is equivalent to this expression: (R.exec (s)!= null).