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'));