Skip to content
Regex for Email Validation — Pattern Explained with Examples

Regex for Email Validation — Pattern Explained with Examples

DodaTech Updated Jun 20, 2026 2 min read

Email validation is one of the most common regex use cases in web forms and user registration systems. This pattern checks for the basic structure of an email address: a local part, the @ symbol, and a domain with at least one dot-separated subdomain and a valid top-level domain.

The Pattern

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

Pattern Breakdown

PartMeaning
^Start-of-string anchor
[a-zA-Z0-9._%+-]+Local part: one or more alphanumeric characters plus dots, underscores, percent, plus, and hyphens
@Literal @ separator
[a-zA-Z0-9.-]+Domain name: one or more alphanumeric characters, dots, and hyphens
\.Literal dot before TLD
[a-zA-Z]{2,}Top-level domain: at least two alphabetic characters
$End-of-string anchor

Matches

Does NOT Match

Language Examples

JavaScript

const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
console.log(emailRegex.test('user@example.com')); // true
console.log(emailRegex.test('@example.com'));      // false

Python

import re
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
print(bool(re.match(pattern, 'user@example.com')))  # True
print(bool(re.match(pattern, '@example.com')))       # False

PHP

$pattern = '/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/';
var_dump(preg_match($pattern, 'user@example.com')); // int(1)
var_dump(preg_match($pattern, '@example.com'));      // int(0)

Common Pitfalls

  • Overly strict regexes reject perfectly valid emails with plus tags or subdomains
  • Very permissive patterns allow inputs like user@com with no TLD dot separation
  • Unicode email support varies — this pattern only covers ASCII
  • The only truly reliable way to validate an email is to send a confirmation message

Real-World Use Cases

  • User registration forms — ensure signups provide a properly structured email address
  • Contact forms — validate user input before sending an automated reply
  • Data import cleaning — filter invalid email entries from CSV or database exports

FAQ

Why can't regex fully validate email addresses?
Email addresses follow RFC 5322, which allows complex local parts including quoted strings, comments, and escaped characters that regex cannot reliably parse. Server-side sending is the definitive check.
Should I use this regex on the client, server, or both?
Always validate on both client and server. Client-side validation provides instant feedback to users, while server-side validation is essential for security — never trust client-only validation.

Related Patterns

Regex for URL Regex for UUID

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro