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

Starting with simple HTML5 validation


The great thing about form validation is that it can be easy or complex to fix—it all depends on the route we take to solve the issues.

The key point here is that we can use jQuery to provide form validation; this is a perfectly adequate solution that will work. However, for the simple validation of fields, such as names or e-mail addresses, there is an alternative: HTML5 validation, which uses the HTML5 constraint validation API.

Note

The constraint validation API makes use of HTML5 attributes such as min, step, pattern, and required; these will work in most browsers, except Safari.

Before I explain the logic within this madness, let's take a quick look at how to modify our demo in order to use this form of validation:

  1. Open up a copy of the basicform.html file in your usual text editor and then look for this line:

    <li>
    <label for="name">Name:</label>
    <input type="text" name="username" required>
    </li>
  2. We need to add the pattern...