JavaScript / ECMAScript

Email Address Validation in JS

Match and validate email addresses in the standard user@domain.tld format.

Try it in the JS tester →

Pattern

regexJS
[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}   (flags: g)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("[a-zA-Z0-9._%+\\-]+@[a-zA-Z0-9.\\-]+\\.[a-zA-Z]{2,}", "g");
const input = "user@example.com";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

Matches a local part (letters, digits, dots, underscores, percent, plus, hyphen) followed by @, a domain name, a dot, and a TLD of at least 2 characters.

Examples

Input

user@example.com

Matches

  • user@example.com

Input

hello.world+tag@sub.domain.org

Matches

  • hello.world+tag@sub.domain.org

Input

invalid-email

No match

Same pattern, other engines

← Back to Email Address Validation overview (all engines)