In the Twitter signup process, they do not allow you to input any character other than alphanumeric keywords
What would be a good way, efficient way of doing so? The plugins available seems to be a little too slow for my liking, so i was wondering if anyone had more efficient way of doing so
You can listen for
keydown/keypress, check the character code, and if it’s not something you wantpreventDefault()orreturn falseImplementation
Here’s an example with jQuery. This creates a list of ‘valid’ keycodes, initially populated with formatters (Escape, Backspace etc) and then populates the array with other valid keys.
You can also use this array to check validity of the username before submitting, by iterating through each character in the string and making sure it’s one of these.
Try it out here
http://jsfiddle.net/vRJ2v/