View Full Version : Another Quick Validation Question

03-31-2003, 12: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!");
return false;

if (isNaN(document.form.idnum.value)) {
window.alert ("Your ID Number Must be Numerical and contain 12 Digits!");
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

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

That should do the trick! :)

03-31-2003, 01: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");
return false;

03-31-2003, 02: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