Validation

Email Domain Part (After @)

Validate just the domain portion of an email address — the bit after the @.

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^[a-zA-Z0-9](?:[a-zA-Z0-9.\\-]{0,253}[a-zA-Z0-9])?\\.[a-zA-Z]{2,24}$", "");
const input = "example.com";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

Pattern

regexengine-agnostic
^[a-zA-Z0-9](?:[a-zA-Z0-9.\-]{0,253}[a-zA-Z0-9])?\.[a-zA-Z]{2,24}$

Raw source: ^[a-zA-Z0-9](?:[a-zA-Z0-9.\-]{0,253}[a-zA-Z0-9])?\.[a-zA-Z]{2,24}$

How it works

Starts and ends with alphanumeric per RFC. Allows dots and hyphens in the middle. Length capped at 255 chars total. Trailing \.[a-zA-Z]{2,24}$ requires a TLD of 2–24 characters (covers everything from `.io` to `.international`).

Examples

Input

example.com

Matches

  • example.com

Input

mail.sub.domain.org

Matches

  • mail.sub.domain.org

Input

no-tld

No match

Common use cases

  • Splitting an email and re-validating each half independently
  • Enterprise allowlists (only @company.com)
  • Domain-level analytics on mailing lists
  • Custom-domain validation in SaaS sign-up

Related patterns