I'm working with an input
field of type number
, and I need to stay with this field type (using a text
field is not an option).
The number field blocks most non-numeric characters, the exception being characters like .
, -
, and +
. The field I am working with is only for non-negative integers, so I'm trying to block these by attaching an onkeypress
handler, for example:
$('input[type="number"]').on('keypress', function (ev) {
if (/* keyCode in list of undesired chars */) {
return false; // preventing character from being added
}
}
Is there a definitive list of what characters are permitted, or would I have more luck just enumerating the keycodes which the field does support?
I am aware of solutions like jquery.numeric
but would prefer not to add another dependency.