Regex for email address

Use /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/ to check that a whole string is a valid for email address. Every example below is tested against the pattern, and you can open it in the Regex Tester with the samples preloaded.

Updated

/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/
Open in Regex Tester
InputResult
user@example.com✓ Match
first.last+news@mail.example.co.uk✓ Match
x_y%z@sub.domain.io✓ Match
plainaddress✗ No match
@example.com✗ No match
user@domain✗ No match
user name@example.com✗ No match
user@@example.com✗ No match

How the pattern works

PartMeaning
^Start of the string
[A-Za-z0-9._%+-]+The local part: one or more letters, digits, dots, underscores, percent, plus or hyphen signs
@A literal @
[A-Za-z0-9.-]+The domain name, including subdomains
\.A literal dot before the top-level domain
[A-Za-z]{2,}The top-level domain: two or more letters (com, io, museum)
$End of the string

Code examples

JavaScript

const re = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
re.test(value); // true or false

Python

import re

bool(re.fullmatch(r'[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}', value))

PHP

preg_match('/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/', $value) === 1;

Notes and limitations

This is the practical pattern most sign-up forms use. It accepts some technically odd addresses (two dots in a row) and rejects rare valid ones (quoted local parts, IP-address domains). The only real test of an email address is sending a confirmation link — in HTML forms, <input type="email"> gives you browser validation for free.

Regex TesterType a pattern and watch matches highlight live in your test text.
Open the tool

Frequently asked questions

What is the regex for email address?
/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/ — it matches the whole string. See the table above for what each part does.
Which examples match?
Of the examples tested, these match: user@example.com, first.last+news@mail.example.co.uk, x_y%z@sub.domain.io. The others don’t.
How do I test this regex?
Click “Open in Regex Tester” — the pattern, flags and sample text load automatically, and matches highlight as you edit.