apps-script-utils 2.1.1 Help

isValidLocale

function isValidLocale(value: string): boolean;

Exactly two ASCII letters, in either case — "en", "UK". A region or a script subtag, as in "en-US", is rejected: this is the short language code, not a full BCP 47 tag.

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

value

string

The value to check.

Returns

boolean — true when the value is a locale code; otherwise false.

Examples

What passes and what does not

isValidLocale("en"); // => true isValidLocale("UK"); // => true isValidLocale("en-US"); // => false isValidLocale("eng"); // => false isValidLocale(""); // => false

See also

Source

src/lang/string/isValidLocale.ts

23 September 2026

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