Implementing input character restrictions

Until now, all of the recipes in this chapter have concentrated on input validation and providing appropriate feedback to the user. There are situations where it is better to simply prevent the user from inputting invalid characters in the first place. This method would not typically be used, because it can be confusing for some users; for example, if they are not being told why they cannot input %. A situation where this would work is a login form. If you know your registration system does not allow % in the username, you know that the user would be inputting % by mistake, and therefore preventing the input is acceptable. This recipe provides a method to prevent users from inputting non-alphanumeric characters ...

Get jQuery 2.0 Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.