RegexRef Logo
📧

Regex for Email Address

Validates a standard email address format.

Understanding The Regex Pattern

/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
Test in Visualizer ↗
Matches
  • user@example.com
  • john.doe+test@sub.domain.org
Non-Matches
  • user@.com
  • @missing-user.com
  • user@example

How this Pattern Works

This regular expression is widely used to validate email addresses in web forms, application programming interfaces (APIs), and databases. It strictly checks for the standard format of an email address to ensure data integrity and prevent errors downstream. The pattern expects a local part containing alphanumeric characters, dots, underscores, percents, pluses, or hyphens. This is followed by the mandatory '@' symbol, and then a domain name with a valid top-level domain (TLD) consisting of at least two alphabetical characters.

Implementing this regex helps ensure data integrity by preventing users from accidentally submitting malformed email addresses during registration, checkout, or contact processes. A robust email validation strategy significantly reduces email bounce rates, improves communication reliability, and prevents database clutter caused by invalid entries.

It is important to note that while this regular expression is highly effective for catching common typos and formatting mistakes, it does not perfectly adhere to the official RFC 5322 specification, which is excessively complex and allows for highly unusual email addresses that most modern systems do not support. For the vast majority of web applications, this practical and simplified approach is preferred as it balances strictness with performance and readability. Always remember that the only definitive way to verify if an email address is truly valid and active is to send a confirmation email with a unique verification link.

Implement The Regex In Your Code

javascript
const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
regex.test('user@example.com');
python
import re
regex = re.compile(r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$')
bool(regex.match('user@example.com'))
go
import "regexp"
matched, _ := regexp.MatchString(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`, "user@example.com")
rust
use regex::Regex;
let re = Regex::new(r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$").unwrap();
re.is_match("user@example.com")