RegexJavaScript

Regex Email Example

This regex email example uses a practical validation pattern and tests a small set of candidate strings. It is useful when you need lightweight client-side checks before submitting a form or parsing a text block.

Concise explanation

  • Anchor the pattern with `^` and `$` so the whole string must match, not just part of it.
  • Match the local part before `@` with a practical character set used in many web forms.
  • Require a dot plus at least two letters for the top-level domain.
  • Filter a list of samples to see which strings pass the validation check.

Code snippet

JavaScript

const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$/;

const samples = [
  "[email protected]",
  "[email protected]",
  "missing-at-sign",
  "dev@localhost",
];

const matches = samples.filter((value) => emailPattern.test(value));

console.log(matches);

Quick result

Well-formed email strings match the pattern, while incomplete or local-only values are excluded by the domain rules.

Non-matches

missing-at-signdev@localhost

This is a pragmatic front-end validation regex, not a full RFC-complete email parser.

Related examples

Related Tools

What This Email Regex Covers

This pattern covers the email formats most developers care about in product forms and validation flows. It checks for a valid local part, an `@` separator, and a domain that ends in a top-level domain.

That keeps the rule simple enough to understand while catching obvious mistakes before a form is submitted.

Where Regex Email Validation Stops

Email validation is a classic case where practical validation and full protocol correctness are different goals. A lightweight regex is useful for UX, but it should not be the only validation step if the backend depends on email correctness.

In production systems, pair a front-end regex with server-side validation and, when necessary, email verification flows.