I am working on a text field that works with validation, which will not allow you to enter values other than numeric values. So my initial code looked pretty simple and similar to this:
$(textField).onKeyPress(function(e) {
if (e.which < 48 && e.which > 57)
e.preventDefault();
});
It is quite complicated, but turns it (in the latest version of all browsers) Firefox will also do this by preventing movement with the arrow keys and the delete / return keys, while other browsers will not.
Looking around, I found that I would also need to check these keys and check the various properties found in e.
My last code looks something like this:
$(textField).onKeyPress(function(e) {
var code = e.which || e.keyCode;
if (code > 31
&& (code < 37 || code > 40)
&& (code < 48 || code > 57)
&& (code != 46)
)
e.preventDefault();
});
However, this seems too complicated to solve a rather simple problem, as it simply prevents a non-numeric number.
? ?