Web Analytics Made Easy -
StatCounter Numeric Range Validation PLEASE HELP ASAP - CodingForum

Announcement

Collapse
No announcement yet.

Numeric Range Validation PLEASE HELP ASAP

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

  • Numeric Range Validation PLEASE HELP ASAP

    Hey guys,

    I posted this same question a couple of days ago so please excuse me for being repetative. I am trying to update the code you see below with Numeric Validtion. This is a function that is called to verify a numeric field. But for my life I cant figure it out. I have attached the code below. All I am trying to do is update the code to allow a numeric range from 0 - 35000.. But still have the function do what it is already doing. Please help ASAP, I have to get this working by this afternoon. PLEASE HELP.. THANKS GUYS!

    Code:
     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
    I thought we had dealt with this. The code you have bears little relation to what you are wanting - it validates certain letters rather than numbers.

    function testNumeric {
    var isValid = false;
    var txt = document.getElementById(tb).value;
    if (/^\d{1,5}$/.test(txt.value) { /// match 1-5 digits and nothing but (no decimals)
    isValid = true; // passes this stage
    }
    // Then test the number for >0 and less than 35000

    if (txt.value <1 || txt.value >35000)
    {
    isValid= false;
    alert ("Invalid Input");
    }
    }
    Last edited by Philip M; Oct 7, 2006, 11:20 AM.

    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