Book Image

jQuery 2.0 Development Cookbook

By : Leon Revill
Book Image

jQuery 2.0 Development Cookbook

By: Leon Revill

Overview of this book

Table of Contents (17 chapters)
jQuery 2.0 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 into an input field.

Getting ready

This recipe does not use any code from the last eight recipes; however, there are similarities in the CSS code. To complete this recipe, you are going to need three files. Create recipe-9.html, recipe-9.js...