ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Form Validation
Subject:   Phone validation in error
Date:   2003-01-30 14:20:38
From:   anonymous2
Very good script overall and lucid explanation. However, the phone script accepts alpha characters (up to nine) for the phone number as long as the first character is numeric.


Here is the validation chunk for the phone number:
****************************************
// phone number - strip out delimiters and check for 10 digits


function checkPhone (strng) {
var error = "";
if (strng == "") {
error = "You didn't enter a phone number.\n";
}


var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
if (isNaN(parseInt(stripped))) {
error = "The phone number contains illegal characters.";

}
if (!(stripped.length == 10)) {
error = "The phone number is the wrong length. Make sure you included an area code.\n";
}
return error;
}
***********************************************
Any ideas?


Mike Sivertsen
Web Architect


1 to 1 of 1
  1. Phone validation in error
    2003-08-01 15:11:16  anonymous2 [View]

1 to 1 of 1