Home

Saturday, October 15, 2011

only numeric input validation in javascript



<script type="text/javascript">
function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
if (unicode<48||unicode>57) //if not a number
return false //disable key press
}
}
</script>

<form>
<input type="text" size=18 onkeypress="return numbersonly(event)">
</form>

No comments:

Post a Comment

rathoddhirendra.blogspot.com-Google pagerank and Worth