I have a form text field that I want to allow only numbers and letters in. (i.e., no #$!, etc…) Is there a way to throw up an error and prevent the keypress from actually outputting anything if the user tries to use any character other than numbers and letters? I’ve been trying to find a plugin, but haven’t really found anything that does this…
Share
EDIT:
There are some other good answers here that will prevent the input from taking place.
I’ve updated mine since you also wanted to show an error. The replace can take a function instead of a string. The function runs and returns a replacement value. I’ve added an
alertto show the error.http://jsfiddle.net/ntywf/2/