Validate Email Address Syntax in Javascript

A simple regular expression to validate that an email address is syntactically correct.

const isValidEmail = (email) => {
	const regex = /^[a-zA-Z0-9][a-zA-Z0-9.-]*@([a-zA-Z0-9-]+\.)+[\a-zA-Z0-9-]+$/;
	return email.match(regex) ? true : false;
}

console.log(isValidEmail('myuser@mydomain.com'));

console.log(isValidEmail('myuser@wmydomiain'));

Subscribe to dadonk

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe