How to Use jQuery To Validate an Email Address

How to Use jQuery To Validate an Email Address

Simply, quickly and effectively use jQuery to validate and verify email addresses. Stop bad email addresses before they get into your system. Learn how today.


Let's face it, validating, verifying and checking input data is not what is generally described as a "fun" activity if you're a web developer. This is especially true for email addresses where the sheer quantity of address syntax permutations, allowed characters, new TLDs can make validating any given email address particularly challenging.

Below is a quick start to using one of the most methods to achieve effective email address syntax validation using jquery email validation.

This guide is for anyone who works with designing and deploying web sites and needs to ensure that email addresses input by users are correctly formatted.

Required Scripts

  • jQuery
  • jQuery Validate Plugin

Step 1 - HTML Form

The basic mark-up for a web form with no built in validation.

<form action="" id="form1">
	<label for="email"> Address</label><br/>
	<input type="email" id="email" required="required"/><br/>
	<input type="submit" value="submit"/>
</form>

Step 2 - Scripts

Add the following at the bottom of the page </body> element in the page.

	//... previous page markup stuff
	<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
	<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"</script>
//.. more of your scripts
</body>

Step 3 - Enable Validation

Add jQuery validation to the form.

<script>
$('#form1').validate();
</script>

Here's the whole script put together.

<!DOCTYPE html>
<!-- jquery email validation demo -->
<html>
	<head>
		<title>jQuery Email Validation Demo</title>
	</head>
	<body>
		<form id="form1">
		<label for="email">Email Address</label><br/>
		<input type="email" id="email" required="required"/><br/>
		<input type="submit" value="submit"/>
		</form>
		<script src="https://code.jquery.com/jquery-1.11.2.min.js">
		</script>
		<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"></script>
		<script>
		$('#form1').validate();
		</script>
	</body>
</html>

See an online demo of jQuery email validation in action here

Conclusion

Validating email addresses is a tedious but necessary task for anyone interested in keeping badly formatted email addresses out of their systems.

The jQuery validate plugin offers one of the the best ways of doing simple, effective email syntax validation on a web page.

Another way to check if an email address is valid is to use email verification software like CORE, which identifies email addresses in your data, checks them, keeps your data in the right order and gives clear results. It gives you all the information you need to make the most of your emails.

Get a free trial today and validate your first 100 email addresses.

sign up for a CORE free trial

Related Resources

Rowland

Written by: Rowland

Friday, 23 September 2022
READ TIME: 3 MIN