Pages

Thursday, 13 October 2011

Javascript validate positive integer value with decimal places

This javascript function will allow user to enter integer value with decimal places.

This JavaScript function you can all in onkeypress event of the textbox and it will validate the user entered value in client side.





function allowPositiveNumber(e) {
            var charCode = (e.which) ? e.which : event.keyCode
  
            if (charCode > 31 && (charCode < 46 || charCode > 57 )) {
                return false;
            }
            return true;
 
}

And Below is the HTML Text Box code



<input name="myTextBox" onkeypress="return allowPositiveNumber(event);" /><br>

No comments:

Post a Comment