apps-script-utils 2.1.1 Help

requireValidEmail

function requireValidEmail(email: string | null | undefined, message?: string): string;

The address is split at a single @: the domain is checked the way isValidDomain checks one, and the local part must be non-empty and free of spaces. It is a format check, not proof that the mailbox exists.

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

email

string \| null \| undefined

The string value representing an email to validate. Can be null or undefined.

message (optional)

string

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

Returns

string — the same value, typed as an email address.

Throws

Exception

Condition

InvalidEmailFormatException

the value is not an email address.

Examples

What passes and what does not

requireValidEmail("user@example.com"); // => "user@example.com" requireValidEmail("first.last@sub.example.co.uk"); // => "first.last@sub.example.co.uk" requireValidEmail("user@@example.com"); // throws InvalidEmailFormatException requireValidEmail("user@"); // throws InvalidEmailFormatException

See also

Source

src/lang/string/requireValidEmail.ts

23 September 2026

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