# General Translation Platform: isValidLocale URL: https://generaltranslation.com/en-GB/docs/platform/core/reference/utility-functions/locales/is-valid-locale.mdx --- title: isValidLocale description: Check whether a value is a valid locale code without a GT instance. API reference for isValidLocale. --- [`isValidLocale`](/docs/platform/core/reference/gt-class-methods/locales/is-valid-locale) is a standalone utility function from General Translation's Core library that validates whether a string is a valid BCP-47 locale code. It performs format validation without requiring a GT instance. ## Overview [#overview] Import `isValidLocale` directly from `generaltranslation` and call it with a locale code. It does not require an API key or a [GT](/docs/platform/core/reference/gt-class/constructor) instance. For the instance-based equivalent, use the [`isValidLocale`](/docs/platform/core/reference/gt-class-methods/locales/is-valid-locale) method on a [`GT`](/docs/platform/core/reference/gt-class/constructor) instance instead. ```typescript import { isValidLocale } from 'generaltranslation'; console.log(isValidLocale('en-US')); // true console.log(isValidLocale('invalid')); // false ``` Signature: ```typescript isValidLocale(locale: string, customMapping?: CustomMapping): boolean ``` ## How it works [#how-it-works] * **Format validation.** Validates the BCP-47 locale code format. This is purely format validation — no network requests are made. * **Custom mapping.** Works with custom locale mappings, so aliases defined in a [`customMapping`](/docs/platform/core/reference/types/custom-mapping) are considered valid. * **Stateless.** Suitable for utility libraries and user input validation. ## Parameters [#parameters] | Parameter | Description | Type | Optional | Default | | ---------------------------------- | --------------------------------------------- | --------------------------------------------------------------------- | -------- | ------- | | [`locale`](#locale) | The value to validate. | `string` | No | — | | [`customMapping`](#custom-mapping) | Custom mapping to consider during validation. | [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) | Yes | — | ### `locale` [#locale] **Type** `string` · **Required** The value to validate as a BCP-47 locale code. ### `customMapping` [#custom-mapping] **Type** [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) · **Optional** An optional custom mapping whose aliases are recognised as valid. ## Returns [#returns] **Type** `boolean` `true` if the locale code is valid, `false` otherwise. ## Examples [#examples] ```typescript import { isValidLocale } from 'generaltranslation'; // Valid locale codes console.log(isValidLocale('en-US')); // true console.log(isValidLocale('zh-CN')); // true console.log(isValidLocale('es')); // true // Invalid locale codes console.log(isValidLocale('invalid')); // false console.log(isValidLocale('en_US')); // false (underscore instead of hyphen) console.log(isValidLocale('')); // false ``` ## Notes [#notes] * Validates BCP-47 locale code format. * Works with custom locale mappings. * Essential for user input validation. * No network requests — pure format validation. * Stateless function suitable for utility libraries.