Book Image

Mastering jQuery

By : Alex Libby
Book Image

Mastering jQuery

By: Alex Libby

Overview of this book

<p>Mastering jQuery has been written not only to help maximize your skills with core functionality in the library, but also to explore some of the more intriguing ways of using the library to achieve real-world solutions that could feature on any website or online environment.</p> <p>You'll start with a look at some of the more advanced ways to incorporate the library into your pages, followed by working with forms and advanced form validation using regular expressions. Next you'll move on to animating in jQuery, advanced event handling, and using jQuery effects.</p> <p>Finally, you will develop practical examples of using jQuery with external functionality such as node-webkit, before finishing with a session on optimizing your version of the library for maximum efficiency and exploring best practices for using QUnit.</p>
Table of Contents (21 chapters)
Mastering jQuery
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Validating forms using regex statements


So far, you've seen some of the commands that you can use to validate forms using jQuery, and how you can limit your checks to specific field types (such as e-mail addresses) or override the error message displayed on the screen.

The code will fail though, without some form of validation template that we can use to check—the keen-eyed amongst you may have noticed this, in our basicvalidation.html demo:

pattern = "[^ @]*@[^ @]*\.[a-zA-Z]{2,}";

The pattern variable is used to define a regular expression or a regex statement. Put simply, these are single-line statements that dictate how we should validate any entries in our form. These are not unique to query though; they can be equally used with any scripting language, such as PHP or plain JavaScript. Let's take a moment to look at a few examples in order to see how this one works:

  • [^ @]*: This statement matches any number of characters that are not an @ sign or a space

  • @: This is a literal

  • \.: This is...