Need an input field that will only allow letters or numbers - no symbols
Posted on 2007-09-29
I have an input field which I would like to limit what people can enter to just letters or numbers. I have a similar function that only allows numbers. I just adapted it from a snippet I found online. Here's an example of its use:
<input type="text" name="numbers" onKeyUp="this.value=this.value.replace(/\D/,'');" />
"this.value=this.value.replace(/(?![0-9a-zA-Z])/,'');" would work, but it doesn't - no characters get replaced.
I can't simply use "\W" in place of "\D" because it matches the underscore character, which I don't want.