Email Validation Using jQuery and Regex Examples

Last Updated on August 31, 2022 by Roshan Parihar

In this tutorial, learn email validation using jQuery. The short answer is to use the regular expression with text() to test if it matches the required email format.

You can validate your email address on click outside of the input or by clicking on the submit button. Let’s find out with the examples given below.

Method 1: Validate Email Address Using jQuery with Regex on Click Outside Inputbox

For email validation using jQuery, you must first declare a regular expression for the email address in a variable. After that, use the test() function and pass the regex variable to test whether or not the email address is valid.

The below examples validated the email address when someone entered their email address and click outside of the input box. It uses the focusout() function to detect click outside.

Output

Enter an email address and click outside to validate

When you enter an email address in the input box given above and click outside, it validates the email address and finds out whether it is valid or not.

Method 2: Validate on Click Submit Button in jQuery

In addition to the above example, you can also perform email address validation with the click of the button using click() function. The below example also uses the same text() function with regex expression to test the email validation using jQuery.

To stop the submission of the form on click of the button, it uses the e.preventDefault() function within the if condition as given below.

Output


The above example contains the button and the input box. You can enter an email address in the above input box and click the button for validation using jQuery.

You May Also Like to Read

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.