Email Validation
JavaScript for Email Address Validation
In forms when using email ID fields it is a good idea to use client side validation along with your programming language validation. The following example shows how you can validate an email address for a form. This javascript validation code is cross browser compatible (works for all browsers).
Email Validation Example
Cut and Paste Code
Cut 'n' paste code for the above Example
Explanation of the Code
The JavaScript has two functions:
- Function echeck is used to verify if the given value is a possible valid email address. This function simply verifies the following:
- It makes sure the email address has only one (@) and that it is not at the end or beginning of the email address.
- It makes sure the email address has atleast one (.) after the @.
- atleast one (.).
It also makes sure that there are no spaces, extra '@'s or a
(.) just before or after the @. It also makes sure that there
- Function ValidateForm is used to make sure that the email field is not blank and that it is a valid email address on form submission.