I have this code that only permits numbers to be entered in an input field on keypress()
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
return false;
}
How can I also allow decimals, and minus keypress?
I have this code that only permits numbers to be entered in an input field on keypress()
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
return false;
}
How can I also allow decimals, and minus keypress?
Here is a working demo that checks whether the number is valid or not and also doesn't allow multiple signs:
Allow numbers, decimals, negative
This solution prevents double minuses or dots.
Just add number to input class.
This is a solution, but I recommend to use mask plugin, for example: jQuery-Mask-Plugin