we can check entered keyis numeric or not using javascript coding in our web page.
check example given below:-
Only Numeric key can be Entered :
<html>
<head>
<script type = "text/javascript">
function isNumeric(keyCode)
{
if (keyCode!=8) //if the key is the backspace key
{
if ((keyCode<48||keyCode>57) && (keyCode<96||keyCode>105)) return false;
else
return true;
}
}
</script>
</head>
<body>
Only Numeric key Entered In text Box :
<input type="text" id="txtBox1" onkeydown = "return isNumeric(event.keyCode);"/>
</body>
</html>
Note:
ASCII code for integers 0-9 is 48-57.
ASCII code for extra numeric key pad's integers 0-9 is 96-105.
check example given below:-
Only Numeric key can be Entered :
html code for this:-
<html>
<head>
<script type = "text/javascript">
function isNumeric(keyCode)
{
if (keyCode!=8) //if the key is the backspace key
{
if ((keyCode<48||keyCode>57) && (keyCode<96||keyCode>105)) return false;
else
return true;
}
}
</script>
</head>
<body>
Only Numeric key Entered In text Box :
<input type="text" id="txtBox1" onkeydown = "return isNumeric(event.keyCode);"/>
</body>
</html>
Note:
ASCII code for integers 0-9 is 48-57.
ASCII code for extra numeric key pad's integers 0-9 is 96-105.
No comments:
Post a Comment