Is there a quick way to set an HTML text input () to only allow numeric keystrokes (plus \'.\')?
Please find below mentioned solution. In this user can be able to enter only numeric
value, Also user can not be able to copy
, paste
, drag
and drop
in input.
Allowed Characters
0,1,2,3,4,5,6,7,8,9
Not allowed Characters and Characters through events
$(document).ready(function() {
$('#number').bind("cut copy paste drag drop", function(e) {
e.preventDefault();
});
});
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
Let me know if it not works.