WORKED EXAMPLE / ECMASCRIPT
Practical email address regex
A deliberately practical email check for forms that require one @ sign, a dotted domain, and no whitespace.
Pattern
^[^\s@]+@[^\s@]+\.[^\s@]+$- Flavor
- JavaScript (ECMAScript)
- Flags
- Flags: none
What it does
This pattern catches common typing mistakes without pretending to implement the full email-address specification. It is a useful first-pass format check before confirmation email or server-side validation.
Token-by-token explanation
^Starts matching at the beginning of the input.
[^\s@]+Consumes one or more local-part characters that are neither whitespace nor @.
@Requires the address separator.
[^\s@]+Consumes one or more domain characters before the final dot, excluding whitespace and @.
\.Requires a literal dot in the domain.
[^\s@]+Consumes the final domain segment, such as com or museum, without whitespace or @.
$Stops matching at the end of the input.
Test strings
Matches
reader@example.comfirst.last+notes@sub.domain.co
Does not match
reader@@example.comreader@example
Common mistakes
- Using an enormous RFC-style regex as the only validation step instead of sending a confirmation email.
- Forgetting to anchor the pattern, which can accept an email-looking substring inside invalid text.
Limitations
- It does not implement every quoted local part, domain literal, or other edge case allowed by the email RFCs, and it cannot prove that a mailbox exists.