isValidDomain
function isValidDomain(domain: string): domain is string;
Labels separated by single dots, with no leading or trailing dot or hyphen and no empty label. It is a syntax check: whether the domain resolves is another question.
isX and nonX answer a question and never interrupt control flow; requireX and requireNonX hand the value back or throw. The scheme is explained in Validation conventions.
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The string to check for valid domain name syntax. |
Returns
boolean — true when the value is a domain name; otherwise false.
In TypeScript the guard narrows domain to string inside the branch.
Examples
What passes and what does not
isValidDomain("example.com"); // => true
isValidDomain("sub.example.co.uk"); // => true
isValidDomain("-example.com"); // => false
isValidDomain("example..com"); // => false
isValidDomain("example.com."); // => false
isValidDomain(""); // => false
See also
Source
23 September 2026
This documentation was generated with AI (Claude) from the library's source code.