Regex for Email Validation
Validate email addresses with this regex pattern. Matches standard email formats including local part, domain, and TLD. Free online regex tester tool.
Regular Expression
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/i
Token Breakdown
| Token | Description |
|---|---|
| ^ | Anchors at the start of the string (or line in multiline mode) |
| [a-zA-Z0-9._%+-] | Character class — matches any one of: a-zA-Z0-9._%+- |
| + | Matches the preceding element one or more times (greedy) |
| @ | Matches the literal character '@' |
| [a-zA-Z0-9.-] | Character class — matches any one of: a-zA-Z0-9.- |
| + | Matches the preceding element one or more times (greedy) |
| \. | Matches a literal dot |
| [a-zA-Z] | Character class — matches any one of: a-zA-Z |
| {2,} | Matches 2 or more times |
| $ | Anchors at the end of the string (or line in multiline mode) |
Detailed Explanation
This regex validates standard email address formats. Here is a token-by-token breakdown:
^ — Anchors the match at the start of the string, ensuring nothing precedes the email.
[a-zA-Z0-9._%+-]+ — Matches the local part (before the @). It allows one or more letters (upper or lowercase), digits, dots, underscores, percent signs, plus signs, and hyphens. This covers most valid email local parts.
@ — Matches the literal at-sign separating the local part from the domain.
[a-zA-Z0-9.-]+ — Matches the domain name portion. It allows letters, digits, dots (for subdomains), and hyphens. The plus quantifier requires at least one character.
. — Matches a literal dot before the top-level domain. The backslash escapes the dot so it is not treated as the wildcard metacharacter.
[a-zA-Z]{2,} — Matches the top-level domain (TLD), requiring at least two letters. This accommodates TLDs like .com, .org, .info, and newer ones like .technology.
$ — Anchors the match at the end of the string, ensuring nothing follows the email.
The i flag makes the match case-insensitive, though the character classes already include both cases for clarity. This pattern works well for most real-world email validation but does not cover every edge case in RFC 5322.
Example Test Strings
| Input | Expected |
|---|---|
| user@example.com | Match |
| first.last+tag@sub.domain.org | Match |
| admin@localhost | No Match |
| user@@example.com | No Match |
| name@domain.co.uk | Match |
Try It — Interactive Tester
48 charsFlags: iMatches: 0Ctrl+Shift+C to copy regex
Related Regex Patterns
Regex to Match URLs
/https?:\/\/[\w.-]+(?:\.[a-zA-Z]{2,})(?:\/[\w./?#&=%-]*)*/gi
Regex to Extract Domain Names
/(?:https?:\/\/)?(?:www\.)?([a-zA-Z0-9-]+(?:\.[a-zA-Z]{2,})+)/gi
Regex to Match Mailto Links
/mailto:[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(?:\?[\w=&%.+-]*)?/gi
Regex to Match @Username Mentions
/@([a-zA-Z]\w{0,29})/g