Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    ozz
    ozz is offline
    New Coder
    Join Date
    Mar 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Another Quick Validation Question

    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

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Code:
    if (form.idnum.value.length >12){
    alert("Please enter up to 12 digits!");
    }
    That should do the trick!
    Omnis mico antequam dominus Spookster!

  • #3
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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;
    }

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you're doing alot of validation, you might want to check out my fValidate script

    I'm close to releasing a new major version
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •