Web Analytics Made Easy -
StatCounter Numeric Validation Help - CodingForum

Announcement

Collapse
No announcement yet.

Numeric Validation Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Numeric Validation Help

    Hello everyone, I'm new to this forum so hopefully you guys can help me and also I may help you guys . I am modifying a java script that has a function to validate a numeric value. I am attempting to update this function to validate numeric ranges for example =>0 to 35000.

    Drawing a blank here on how to do this.. Any help would be greatly apprecaited. I have included the function that I am changing.. Thank you everyone.

    Signed
    The New Guy

    function DrawNumericValidation(source, args){
    var tb = source.id.split("-")[0];
    var txt = document.getElementById(tb).value;
    txt = txt.replace(/ /g,"");
    document.getElementById(tb).value = txt;

    args.IsValid = true;

    if (txt == null || txt.length == 0) {
    args.IsValid = true;
    }
    else {
    for (var i = 0; i < txt.length; i++) {
    var c = txt.charCodeAt(i);
    if ((c < 48 || c > 57) && c != 46) {
    args.IsValid = false;
    }
    }
    }

  • #2
    This is a terribly complicated and long way round to achieve what you want.

    First, validate the input is a number (say 1-5 digits) using a regular expression:-

    if (/^\d{1,5}$/.test(theTextBox.value)) { /// match 1-5 digits and nothing but (no decimals)

    Then test the number for >0 and less than 35000

    if (theTextBox.value <0 || the TextBox.value >35000)
    {alert ("Invalid Input");
    }

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

    Comment

    Working...
    X