Click to See Complete Forum and Search --> : Javascript field validation code help


Nicodareus
08-28-2003, 03:25 PM
Greetings-- I have a field in my form that I need validated. Currently it is a 10 digit number, however the first 3 numbers must begin with either "003", "999", "099" or "333". How could I make a validation to check just the first three numbers in the string to make sure they are one of the above numbers?

If that can't be done, should I just break up the field into 2 values and have the first 3 numbers in its own seperate field and the trailing 7 be in another? If so, how would I write the validation script to check for != 003,999,099,333 and return false?

Thanx a bunch for the help

Nico

Charles
08-28-2003, 03:32 PM
<input type="text" onchange="if (!/^((003)|(999)|(099)|(333))\d{7}$/.exec(this.value)) {alert('That would not appear to be a valid number.'); this.value=''; this.focus()}">

Nicodareus
08-28-2003, 05:10 PM
That worked perfectly. Thanx very much!

Nico