Back to Blog
Developer Tools

Regex Email Validation Pattern โ€” The Right Pattern for Real-World Use

2026-06-03 5 min read

Email regex is surprisingly tricky. Here is a practical pattern that catches common errors without rejecting valid unusual email addresses.

Email validation with regex is one of those things that looks simple but has a lot of edge cases. Most regex patterns you find online either reject valid addresses or accept invalid ones. Here's what actually works and why.

The practical regex for email validation

For most applications, this pattern works well:

const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$/;

// Usage
emailRegex.test("user@example.com")       // true
emailRegex.test("user+tag@subdomain.example.co.uk") // true
emailRegex.test("invalid@")              // false
emailRegex.test("@example.com")          // false
emailRegex.test("notanemail")            // false

What each part does

  • ^ โ€” Start of string
  • [a-zA-Z0-9._%+\-]+ โ€” Local part: letters, digits, dots, underscores, percent, plus, hyphen
  • @ โ€” The @ symbol
  • [a-zA-Z0-9.\-]+ โ€” Domain: letters, digits, dots, hyphens
  • \.[a-zA-Z]{2, โ€” TLD: dot followed by at least 2 letters
  • $ โ€” End of string

Why perfect email regex is impossible

The full email specification (RFC 5321/5322) allows things like: "quoted strings"@example.com, addresses without TLDs on private networks, and comments inside addresses. A regex that fully complies with the spec is hundreds of characters long and almost never what you actually want.

The pragmatic approach: validate basic format with regex, then send a confirmation email. If they get the confirmation email, the address works. That's the only reliable validation.

HTML5 email input type

The browser's built-in email validation is often good enough for forms:

<input type="email" name="email" required />

// Or with the pattern attribute for stricter control
<input type="email" pattern="[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}" />

This handles basic validation with no JavaScript needed. Still validate server-side too because front-end validation can always be bypassed.

Test your regex patterns live with our Regex Tester.

regex email validation pattern javascript

More Articles