^[^\s@]+@[^\s@]+\.[^\s@]+$ This pattern performs a pragmatic sanity check on email addresses: one or more non-space, non-at characters, an @ symbol, a domain part, a dot, and a top-level domain. It catches the overwhelming majority of typos without pretending to implement the full RFC 5322 grammar. Validation patterns answer a yes/no question about an entire input: does this string conform to the expected format? They are anchored with ^ and $ so the whole value must match, and they belong at the edge of your system — form fields, API payloads and import files — where rejecting bad input early prevents downstream errors. A validation regex is a contract check, not a transformation. It needs no special flags. Apply it to the whole input as a format contract. It deliberately rejects valid-but-exotic RFC 5322 addresses (quoted local parts, IP literals, comments) because those are rare and usually mistakes. A passing regex does not prove the mailbox exists — always send a verification email for real confirmation. Internationalized addresses (Unicode local parts) need a Unicode-aware pattern or a dedicated library; this ASCII-oriented form will reject them. As with any regular expression, confirm its behavior in your target engine, test boundary and adversarial inputs, and watch for catastrophic backtracking before relying on it in production.
Token-by-token explanation
^ — anchor to the start of the string[^\s@]+ — local part: any run of characters except whitespace and @@ — the literal at-sign separating local part and domain[^\s@]+ — domain labels without spaces or @\. — a literal dot before the top-level domain[^\s@]+$ — TLD characters up to the end anchor
What it matches
ada@example.comgrace.hopper@navy.miluser+tag@sub.domain.co.uk What it does not match
plainaddress@no-local.comuser@user@domaintwo@@at.com When to use it
Reach for a validation pattern when data crosses a trust boundary: a signup form, an API request body, a CSV import or a configuration value. Run it before any processing so malformed input is rejected with a clear message instead of causing a cryptic failure later. Keep the pattern in one shared place, document the exact format it accepts, and pair it with a real parser when the value has semantics (dates, numbers, addresses) that a shape check alone cannot confirm.
Caveats
- It deliberately rejects valid-but-exotic RFC 5322 addresses (quoted local parts, IP literals, comments) because those are rare and usually mistakes.
- A passing regex does not prove the mailbox exists — always send a verification email for real confirmation.
- Internationalized addresses (Unicode local parts) need a Unicode-aware pattern or a dedicated library; this ASCII-oriented form will reject them.
Code examples
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const input = "ada@example.com";
if (re.test(input)) {
// valid: proceed
} else {
// reject with a helpful message
} import re
rx = re.compile(r"^[^\s@]+@[^\s@]+\.[^\s@]+$")
value = "ada@example.com"
if rx.fullmatch(value):
pass # valid
else:
raise ValueError("invalid format") import java.util.regex.*;
Pattern p = Pattern.compile("^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$");
Matcher m = p.matcher("ada@example.com");
boolean ok = m.matches(); // whole input must conform <?php
$subject = "ada@example.com";
if (preg_match('/^[^\s@]+@[^\s@]+\.[^\s@]+$/', $subject, $m)) {
// $m[0] is the full match
} How to test it
Before trusting any pattern, test it against three kinds of input: valid examples that must match, invalid examples that must be rejected, and edge cases at the boundaries (empty strings, maximum lengths, unusual separators and Unicode). Paste the expression into a live regex tester with your actual sample data and confirm the highlighted matches are exactly what you intend. Watch for catastrophic backtracking by trying long non-matching inputs, and remember that engine differences (JavaScript, Python, Java, PCRE, Go/RE2) mean a pattern that works in one may fail or behave differently in another — especially lookarounds, which Go's RE2 does not support at all.
Frequently asked questions
Why not use the full RFC 5322 email regex?
The complete grammar is enormous, allows constructs almost nobody uses, and is prone to catastrophic backtracking. A simple sanity check plus a verification email is more reliable and maintainable.
Does this accept user+tag@gmail.com?
Yes — the plus sign is allowed in the local part because [^\s@] only excludes whitespace and @, so sub-addressing tags pass correctly.
Should validation regexes be anchored?
Yes — use ^ and $ (or fullmatch) so the entire input must conform. Without anchors, a valid-looking substring inside garbage would pass, letting malformed data through your validation layer.
What is catastrophic backtracking and how do I avoid it?
Nested quantifiers like (a+)+ can explode exponentially on non-matching input, freezing the engine (ReDoS). Avoid ambiguous nesting, prefer atomic groups or possessive quantifiers where supported, and bound input length.
Try the Regex Tester
Live regex matching with groups, flags and explanations.