JavaScript Tutorial Phone number verification
The following check function, if the phone number is valid. At first we used the regular expression and the replace () method
To clear any interval character. Next, we use the isNaN () function to check that the phone number contains only numbers
。 Finally we check the string length and license, with only 10 digits of the phone number.
function Validatephone (FLD) {
var error = "";
var stripped = Fld.value.replace (/[().-]/g, ");
if (Fld.value = = "") {
Error = "You didn ' t enter a phone NUMBER.N";
Fld.style.background = ' yellow ';
else if (isNaN (parseint (stripped)) {
Error = "The phone number contains illegal CHARACTERS.N";
Fld.style.background = ' yellow ';
Or else if (! Stripped.length = = 10)) {
Error = "The phone number is the wrong length. Make sure
Included an area CODE.N ";
Fld.style.background = ' yellow ';
}
Return
Error
}