Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form validation question

Status
Not open for further replies.

dude333

Programmer
Feb 5, 2004
11
GB
Hi,

Can anyone tell me the most effective way to validate the form input from one field under the following criteria.

The data inputted must be in the range 00-24. ie, I do not want anyone to input 9 it must be 09.

Obviously I could write a large set of if statements to check input, but is there a more effective way to do this?

I have found info on RegExp's but no clear example using numbers like this. Does anyone have a link to a good example of RegExp statement that checks numbers?

Thanks.


 
Code:
function isValid(s) {
  return /^(0|1)[0-9]$|^2[1-4]$/.test(s);
}

<input type="text" onblur="alert(isValid(this.value));" />

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Thanks for that, just what I was looking for.

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top