Numeric Validation using TextBox OnKeyPress event in JavaScript.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 440
Write below code:-
In the below function,48 is for 0,49 for 1 and 57 is for 9
<script type = "text/javascript">
var specialKeys = new Array();
specialKeys.push(8); //Backspace

function Check_Is_Numeric(e)
{
var keyCode = e.which ? e.which : e.keyCode;
var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);
document.getElementById("error").style.display = ret ? "none" : "inline";
return ret;
}
</script>
<input type = "text" id = "text1" onkeypress = "return Check_Is_Numeric(event);" ondrop = "return false;" onpaste = "return false;"/>

Comments or Responses

Login to post response