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

  1. ^

    Starts matching at the beginning of the input.

  2. [^\s@]+

    Consumes one or more local-part characters that are neither whitespace nor @.

  3. @

    Requires the address separator.

  4. [^\s@]+

    Consumes one or more domain characters before the final dot, excluding whitespace and @.

  5. \.

    Requires a literal dot in the domain.

  6. [^\s@]+

    Consumes the final domain segment, such as com or museum, without whitespace or @.

  7. $

    Stops matching at the end of the input.

Test strings

Matches

  • reader@example.com
  • first.last+notes@sub.domain.co

Does not match

  • reader@@example.com
  • reader@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.