Is it possible to restrict the input of certain characters in HTML5/JavaScript? For example could I have a input textbox on the screen and if the user tries to type a letter it wouldn't show up in the box because I've restricted it to only numbers?
I know you can use pattern which will check on submit, but I want the "bad" characters to just never be entered at all.
To slightly improve off of jonhopkins excellent answer, I added backspace and delete key acceptance like so:
What about this (it supports special keys, like copy, paste, F5 automatically)?
Use html5 pattern attribute for inputs:
OR
Use html5 number type for input :
For Restricting Characters symbols like '-' and ','
for restricting numbers
for restricting alphabets