Javascript validate text box to enter only number
<script type="text/javascript">
function validate(evt) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode( key );
var regex = /[0-9]|\x08/;
if( !regex.test(key) ) {
theEvent.returnValue = false;
if(theEvent.preventDefault) theEvent.preventDefault();
}
}
</script>
<input type="text" name="afroz" value="" onkeypress='validate(event)' >
//When you enter any text , decimal or special character in the text box it will not be entered. Only numbers
and backspace are allowed. Even decimal is restricted tto enter.
<script type="text/javascript">
function validate(evt) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode( key );
var regex = /[0-9]|\x08/;
if( !regex.test(key) ) {
theEvent.returnValue = false;
if(theEvent.preventDefault) theEvent.preventDefault();
}
}
</script>
<input type="text" name="afroz" value="" onkeypress='validate(event)' >
//When you enter any text , decimal or special character in the text box it will not be entered. Only numbers
and backspace are allowed. Even decimal is restricted tto enter.
thanks you.. i got solutions from http://aspnettutorialonline.blogspot.com/2012/05/textbox-numeric-validation-using-javascript.html
ReplyDeleteThank u very much.. It's work well..
ReplyDeleteThanks all for your valuable support.
ReplyDelete