Skip to content

Validate email address in JavaScript

Find out how to validate an email address in JavaScript.

We can use Regular Expression to check if an email address is valid.

The regular expression /^([a-zA-Z0-9_.-])+\@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/ check if an email address is in the format address@domainname.tld.

function checkMail(email){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
		return true;
	return false;
See also  How to return multiple values from a JavaScript function?

Leave a Reply

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.