apps-script-utils 2.1.1 Help

requireValidDomain

function requireValidDomain( domain: unknown, message: string = "Expected a valid domain name." ): 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

domain

unknown

The value to validate as a domain name.

message (optional) = "Expected a valid domain name."

string

The message of the exception. A default is used when omitted.

Returns

string — the same value, typed as a domain name.

Throws

Exception

Condition

IllegalArgumentException

the value is not a domain name.

Examples

What passes and what does not

requireValidDomain("example.com"); // => "example.com" requireValidDomain("sub.example.co.uk"); // => "sub.example.co.uk" requireValidDomain("-example.com"); // throws IllegalArgumentException requireValidDomain("example..com"); // throws IllegalArgumentException

See also

Source

src/net/path/requireValidDomain.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.