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
| Address | Simple | Browser (HTML) |
|---|---|---|
ada@example.com | Yes | Yes |
first.last+tag@sub.example.co.uk | Yes | Yes |
user@localhost | No | Yes |
ada@-example.com | Yes | No |
two@@example.com | No | No |
space in@example.com | No | No |
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.