Savvion Help

Do you need help on Savvion?
E-mail us on for any information, help, how-to or questions and we will contact you and reply to your question as soon as possible.

Friday, August 19, 2011

Custom JavaScript phone number validation

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: