...

View Full Version : Another Quick Validation Question



ozz
03-31-2003, 01:17 PM
How would I go about validating this field so that it only accept exactly 12 numbers

if (document.form.idnum.value=="") {
window.alert ("Please enter your ID Number!");
document.form.idnum.focus();
return false;
}

if (isNaN(document.form.idnum.value)) {
window.alert ("Your ID Number Must be Numerical and contain 12 Digits!");
document.form.idnum.focus();
return false;
}

hte form validates ok at present for a null value and a numerical value but i would like it to validate for 12 only as well... TIA

Mhtml
03-31-2003, 01:42 PM
if (form.idnum.value.length >12){
alert("Please enter up to 12 digits!");
}

That should do the trick! :)

arnyinc
03-31-2003, 02:57 PM
If exatly 12 is always required, you can make sure it is the same.

if (document.form.idnum.length==12) {
window.alert ("Must be exactly 12 characters");
document.form.idnum.focus();
return false;
}

beetle
03-31-2003, 03:37 PM
If you're doing alot of validation, you might want to check out my fValidate (http://www.peterbailey.net/fValidate/) script :D

I'm close to releasing a new major version



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum