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:
Add the additional
hasClass
check andif
statement to the mainfor
loop invalidation.js
as follows:if ($(input).hasClass('email') && !validateEmail($($(input)).val())) { addErrorData($(input), "Invalid email address provided"); isError = true; }
Add the following
validateEmail()
function to the end ofvalidation.js
:function validateEmail(value) { if (value !=...