I want to use an if-statement to run code only if the user types in a letter or a number.
I could use
if(event.keyCode == 48 || event.keyCode == 49 || event.keyCode == 50..) {
// run code
}
Is there an easier way to do this? Maybe some keycodes don't work in all web browsers?
use
$.isNumeric(value);
return type is booleanAs @Gibolt said, you should Use event.key
Because charCode, keyCode and Which are being deprecated.
For Numeric Values:
Here, 48 and 57 is the range of numeric values.
For Alphabetic:
Here, 65 to 90 is the range for Capital alphabates (A-Z) and 97 to 122 is range for small alphabates (a-z)
You can also use charCode with onKeyPress event: