JAVASCRIPT

Validate Email Address Format with Regex

A robust JavaScript regular expression snippet to accurately validate the common format of email addresses, ensuring correct input in web forms and applications.

const isValidEmail = (email) => {
  const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
  return emailRegex.test(email);
};

console.log(isValidEmail("[email protected]")); // true
console.log(isValidEmail("invalid-email")); // false
How it works: This JavaScript function uses a regular expression to check if a given string conforms to a standard email address format. It validates for common characters before and after the '@' symbol, and a domain name with at least a two-letter top-level domain. This is essential for client-side form validation.

Need help integrating this into your project?

Our team of expert developers can help you build your custom application from scratch.

Hire DigitalCodeLabs