This is a discussion on "Number validation in form field" within the JavaScript Forum section. This forum, and the thread "Number validation in form field are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Number validation in form field
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Number validation in form field
Im working thorugh a variety a javascript problems and have managed to crack them - BUT ONE!
The problem is im trying to get a field to validate the number a user puts in it The number of digits the user puts in will always be 6. However the 1st number must be either a 1 or 2. As 3 and onwards will be used for other sites. Anyone got any suggestions? Much thanks Mat |
|
|
|
|||
|
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. |
|
|||
|
Re: Number validation in form field
Thanks Geoff
Also just done it this way also, no one can enter a 5 digit code now and it cant be above 29999 also Quote:
|
![]() |
| Tags |
| number, validation, form, field |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [SOLVED] playing with Perl Compatible Regex in field validation | eon201 | JavaScript Forum | 33 | Oct 26th, 2007 15:07 |
| [SOLVED] Field validation and changing display properties... | c_martini | JavaScript Forum | 12 | Sep 25th, 2007 11:27 |
| Non-text field Validation | NewDesigner | JavaScript Forum | 6 | Nov 24th, 2006 22:34 |
| date, email and number or character validation | ntgcmlfu | Classic ASP | 5 | Jul 30th, 2006 15:32 |
| Field Validation HELP! | Monie | JavaScript Forum | 5 | Nov 11th, 2004 19:46 |