View Single Post
  #2 (permalink)  
Old May 26th, 2006, 13:15
ukgeoff ukgeoff is offline
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Number validation in form field

The field content is always treated like a string even if its a number.

Therefors you can use string function to check the length of the number, ie, that it's six digits long and you can check that the sub-string, ie, the first character is one of the required numbers.

You need a combination of:

var checkStr = new String(document.getElementById('fieldID').value);

checkStr.length == 6;

checkStr.charAt(checkStr.0) == 1;

and so forth.
Reply With Quote