Regex for email address validation

No regular expression can fully validate every legal email address. This practical pattern covers the common shape (local part, @, domain, top-level domain) and is good for catching typos in a sign-up form.

The pattern

/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g

The tester opens with this pattern and the examples below already loaded. Nothing you type is uploaded.

How it works

[a-zA-Z0-9._%+-]+
Local part: letters, digits and the symbols . _ % + -
@
The separator.
[a-zA-Z0-9.-]+
Domain name, which may include dots and dashes (sub.example).
\.[a-zA-Z]{2,}
A dot followed by a top-level domain of at least two letters.

Examples

Matches

  • hello@example.com
  • first.last+tag@sub.domain.co.in
  • user_name@example.org

Does not match

  • plainaddress
  • @no-local-part.com
  • missing-domain@
  • user@localhost

Use it in JavaScript

const re = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;

// Find every match in a block of text
const found = text.match(re);

// Validate that a whole value matches (no stray characters around it)
const exact = new RegExp('^(?:' + re.source + ')$', re.flags.replace('g', ''));
const isValid = exact.test(value);

Limits and tips

  • It accepts a few invalid forms, such as consecutive dots (a..b@example.com). Tighten it if that matters to you.
  • It does not handle quoted local parts or internationalised addresses. The only reliable check is sending a confirmation email.
  • Anchor it with ^ and $ when validating a single field, or use the wrapper in the code example below.

Frequently asked questions

Is there a regex that validates every email address?

Not in practice. The full email specification is too permissive. Use a simple pattern to catch typos and a confirmation email to verify the address.

Why does the top-level domain need two or more letters?

Because no valid TLD is a single letter. The {2,} quantifier rejects entries like name@example.c.