Below is simple and powerful custom java script phone number validation function which allows 10 digits for your phone field.
function validatePhone(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
error = "You didn't enter a phone number";
} else if (isNaN(stripped)) {
error = "The phone number contains illegal characters";
} else if (!(stripped.length == 10)) {
error = "The phone number is the wrong length. Make sure you included an area code";
}
return error;
}
The above function will check for 10 digits without allowing you to enter characters. It will also accept ., - and + symbol.
No comments:
Post a Comment