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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Number Validation in JScript in Windows IE 6

    Hi there - I am very new to JScript - and need some help with this form validation.

    I have the following JScript doing some validation for me and I would like to extend the validation.

    At the moment it validates for "is a number" - but I need it to validate the following:
    Is a number, only 2 decimal places, maximum of 10 digits, NO minus values, only full stop allowed as decimal seperator.

    Please can somebody suggest the correct syntax for this function !

    Current Code:-
    <input type="text" name="M0" size="12" class="input" value="" onChange="if (isNaN (this.value)) {alert('KPI Values should contain ONLY NUMBERS...Please check your last entry');this.focus()}>

    I also used this code:-
    function checkForNumeric(field)
    {
    // only allow numbers to be entered
    var checkOK = "0123456789";
    var checkStr = field.value;
    var allValid = true;
    var allNum = "";
    for (i = 0; i < checkStr.length; i++)
    {
    ch = checkStr.charAt(i);
    for (j = 0; j < checkOK.length; j++)
    if (ch == checkOK.charAt(j))
    break;
    if (j == checkOK.length)
    {
    allValid = false;
    break;
    }
    if (ch != ",")
    allNum += ch;
    }
    if (!allValid)
    {
    alert("KPI Values should contain ONLY NUMBERS...Please check your last entry");
    return (false);
    }
    }

    Many thanks in advance

    AikenD
    Last edited by AikenDrum; 09-27-2005 at 11:29 AM.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Regular Expressions is the right tool for this job
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #3
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Realized that

    Thanks - I did think that was the way to go - now I just need the regular expression involved

    Kind Regards

    AikenDrum


  •  

    Posting Permissions

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