Contact
Email Address Regex
This is the practical email pattern most sign-up and contact forms need. It accepts letters, digits and the symbols . _ % + - in the local part, then an @ sign, one or more domain labels separated by single dots, and a top-level domain of at least two letters. Consecutive dots in the domain are rejected, which catches a frequent typo. It works well for newsletter forms, checkout pages and CRM imports. The honest limit is that it is a pragmatic subset, not the full RFC 5322 grammar, so quoted local parts and IP-literal domains are not accepted.
Pattern (JavaScript)
/^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$/Starts at the start of the line/string, then one of the characters A-Za-z0-9._%+-, one or more times, then the character "@", then one of the characters A-Za-z0-9-, one or more times, then (the character ".", then one of the characters A-Za-z0-9-, one or more times), zero or more times, then the character ".", then a letter, 2 or more times, then the end of the line/string.
Limit: Practical pattern, not full RFC 5322; it checks the format only and cannot tell whether a mailbox exists.
Examples
Matches
- ✓ ali.test@example.com
- ✓ first+tag@mail.example.org
- ✓ user_99@sub.example.test
Does not match
- ✗ user@
- ✗ user@example
- ✗ user name@example.com
- ✗ user@example..com
Try it
0 matches (JavaScript engine)
ali.test@example.com
first+tag@mail.example.org
user_99@sub.example.test
user@
user@example
user name@example.com
user@example..comCode in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$/g;
const text = "ali.test@example.com";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$')
text = 'ali.test@example.com'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$/';
$text = 'ali.test@example.com';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\\.[A-Za-z0-9-]+)*\\.[A-Za-z]{2,}$");
String text = "ali.test@example.com";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$`)
text := "ali.test@example.com"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$");
var text = "ali.test@example.com";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$").unwrap();
let text = "ali.test@example.com";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$/
text = 'ali.test@example.com'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why not use the full RFC 5322 email regex?
- The full grammar allows quoted strings, comments and IP-literal domains that almost no real users type, and the resulting regex is enormous and hard to maintain. A practical pattern plus a confirmation email is the standard approach.
- Does this pattern accept internationalised email addresses?
- No, it only accepts ASCII characters. If you need addresses with non-Latin letters, use Unicode property escapes such as \p{L} with the u flag, or rely on a dedicated email library.
- How do I find email addresses inside a paragraph?
- Remove the ^ and $ anchors and add the g flag, optionally wrapping the pattern in \b word boundaries. Then use matchAll or a find-all function in your language.
Related patterns
- Australian Mobile Number^(?:\+61 ?|0)4[0-9]{2} ?[0-9]{3} ?[0-9]{3}$
- US Phone Number^(?:\+1[ .-]?)?\(?[2-9][0-9]{2}\)?[ .-]?[2-9][0-9]{2}[ .-]?[0-9]{4}$
- Canada Postal Code^[ABCEGHJ-NPRSTVXY][0-9][ABCEGHJ-NPRSTV-Z] ?[0-9][ABCEGHJ-NPRSTV-Z][0-9]$
- Fax Line with Label^(?:fax|f)\s*[:.]?\s*\+?[0-9(][0-9 ().-]{6,}[0-9]$