Adding e-mail address validation

E-mail address validation is one of the most common types of validation on the Web. Most people would believe that a valid e-mail address only contains alphanumeric characters with the exception of the @ symbol and a full stop. While most e-mail addresses are typically of this format, a valid e-mail address can actually contain a variety of other characters. This recipe will show you how to add e-mail validation to the web form we have been using in the last four recipes.

How to do it…

Create e-mail validation that can be reused again and again by performing the following instructions:

  1. Add the additional hasClass check and if statement to the main for loop in validation.js as follows:
    if ($(input).hasClass('email') ...

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.