Validate email address in jQuery or JavaScript

Form validation is essential part of programming. We can validate email address in jQuery or JavaScript using regular expression. In this article, both are explained. You can check the live demo as well.

Using regular expressions is probably the best way for email validation. The JavaScript function below returns true if given string is an email address otherwise returns false:

Alert: JavaScript can easily be disabled. So keep in mind that one should not rely only upon JavaScript validation. This should be validated on the server side as well.

Validate email address in JavaScript

The following code is an example of email validation using JavaScript. Place the following code between opening and closing tags of your page:

View Demo

Validate email address in jQuery

The same can be achieved in jQuery. Everything will be same except we have included jQuery library and replaced code in isEmail function:

See the live example here.

So here you see it’s quite easy to validate email address with help of regular expression. Your comments and questions are most welcome!

You Might Interested In

Leave a Reply

Enclose a code block like: <pre><code>Your Code Snippet</code></pre>.