Regex tester

Regex for email validation

For most forms, this pattern is all you need: it checks for something, an @, something, a dot and something, with no spaces. It catches typos without rejecting real addresses.

^[^\s@]+@[^\s@]+\.[^\s@]+$

The tester below has the pattern and a list of sample addresses loaded. Matching lines are listed in the result; lines that aren't listed failed.

Regex tester
Test textTEXT

Press Command or Control plus Enter to run. Tab inserts indentation; press Escape, then Tab, to leave the editor.

Result
Your result will appear here.
Ready6 lines · 113 chars

The pattern browsers use for type="email"

The HTML standard defines the exact check browsers run on <input type="email">. Use it when you want your server to accept exactly what the browser accepts. Unlike the simple pattern, it allows addresses without a dot in the domain, such as user@localhost, and rejects domains that start or end with a hyphen.

^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$

What each pattern accepts

AddressSimpleBrowser (HTML)
ada@example.comYesYes
first.last+tag@sub.example.co.ukYesYes
user@localhostNoYes
ada@-example.comYesNo
two@@example.comNoNo
space in@example.comNoNo

Use it in JavaScript

const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

EMAIL.test("ada@example.com");   // true
EMAIL.test("ada@example");       // false

// Trim first: pasted addresses often carry a trailing space.
const isEmail = (value) => EMAIL.test(value.trim());

Why not a "complete" email regex?

  • The full email grammar (RFC 5322) allows quoted local parts, comments and IP-address domains. A regex for all of it is thousands of characters long and still can't tell you whether the mailbox exists.
  • Overly strict patterns reject real addresses, most often ones with + tags, long new domains like .photography, or subdomains.
  • The only real proof is sending a confirmation email. Use the regex to catch typos, then confirm.

Frequently asked questions

Does this regex allow plus addressing like ada+news@example.com?

Yes. Both patterns allow + in the part before the @, which many people use to filter mail.

Should I lowercase emails before saving them?

Lowercasing the domain is always safe. The part before the @ is technically case-sensitive, but almost no provider treats it that way, so most apps lowercase the whole address and compare it case-insensitively.

Why do I need the m flag in the tester?

The samples are on separate lines. With m, ^ and $ match at the start and end of each line instead of only the start and end of the whole text. In a form, where you test one value, you don't need it.

More regex tester guides

Open the full regex tester →

From the blog