Email Domain Part (After @) in JS
Validate just the domain portion of an email address — the bit after the @.
Try it in the JS tester →Pattern
regexJS
^[a-zA-Z0-9](?:[a-zA-Z0-9.\-]{0,253}[a-zA-Z0-9])?\.[a-zA-Z]{2,24}$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).
How the pattern 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.comMatches
example.com
Input
mail.sub.domain.orgMatches
mail.sub.domain.org
Input
no-tldNo match
—