If you need only float or numeric value to be enter in the text box. You can use the below code.
<input name="score" id="score" type="text">
<script>
$(document).ready(function() {
$("#score").keydown(function(event) {
//alert(event.keyCode);
// Allow only backspace, delete, dot, arrow key and numeric value
if ((event.keyCode > 95 && event.keyCode < 106) || (event.keyCode > 47 && event.keyCode < 58) || (event.keyCode == 190 || event.keyCode == 110 || event.keyCode == 8 || event.keyCode == 46 || event.keyCode == 37 || event.keyCode == 39)) {
// let it happen, don't do anything
}
else { // Ensure that it is a number and stop the keypress
event.preventDefault();
}
});
});
</script>
NOTE :: This text box will allow only numeric or float value, if you enter any alphabetic key or special character it will not be accepted.
0 Comment(s)