Validation

Email Address Validation

Validate that a whole string is an email address in the standard user@domain.tld format.

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^[a-zA-Z0-9._%+\\-]+@[a-zA-Z0-9.\\-]+\\.[a-zA-Z]{2,}$", "");
const input = "user@example.com";
const match = input.match(re);
console.log(match ? match[0] : null);

Uses `String.prototype.match`, which returns the first match or null.

Pattern

regexengine-agnostic
^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$

Raw source: ^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$

How it works

Anchored with ^ and $ so the entire input must be the address — without them, "contact: user@example.com" would pass. 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. To find emails inside longer text instead, drop the anchors and add the g flag.

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

—

Input

contact: user@example.com

No match

—

Common use cases

  • •Form input validation
  • •Validating email fields in API request payloads
  • •Filtering and de-duplicating contact lists

Related patterns

Related concepts