phone number validation

Results 1 to 2 of 2

Thread: phone number validation

  1. #1
    Join Date
    Dec 1969

    Default phone number validation

    Hi - I was hoping someone could help me. I have the following function which tests to see if a phone number is a number. The problem is that it won&#039;t allow the user to input dashes or spaces. Does anyone know how I can change the function in order to allow users to input dashes or spaces into their phone number. Thanks in advance.<BR>Corinne<BR><BR><BR>function numeric1 () {<BR> var newval1 =;<BR> for (var i=0; i != newval1.length; i++) {<BR> if ((newval1.charAt (i) &#060; "0") &#124&#124 (newval1.charAt (i) &#062; "9")) {<BR> return false;<BR>}<BR>}<BR> return true;<BR> }

  2. #2
    Dan Evans Guest

    Default RE: phone number validation

    Try changing the IF line so it reads like below. It checks whether temp (the character) is "-" or " " or a digit between 0 and 9, returning false if it isn&#039;t.<BR><BR>function numeric1 () {<BR> var newval1 =;<BR> for (var i=0; i != newval1.length; i++) {<BR> temp = newval1.charAt(i);<BR> if (temp == "-" &#124&#124 temp == " " &#124&#124 (temp &#062;= "0" && temp &#060;= "9")) {<BR> //Great, valid number<BR> } else return false;<BR> }<BR> return true;<BR>}<BR><BR>Hope this helps,<BR><BR>-Dan Evans

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts