bcp47-validate
v1.0.0
Published
Simple validator for BCP47 locale tags
Downloads
5,292
Maintainers
Readme
bcp47
Simple validator for BCP47 locale tags
Helpful resources:
- http://www.w3.org/International/questions/qa-choosing-language-tags
- https://tools.ietf.org/html/bcp47
- http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
Usage
Install
$ npm i @safetyculture/bcp47 --save
Importing
import {validate, pattern} from 'bcp47';
Properties
pattern
A regular expression for validating locale strings
// use with third party validation tools
Joi.string().regex(pattern)
// or just regex
pattern.test(locale);
Methods
validate(locale
) => Boolean
Validate a given locale string.
locale
. Exampleen-US
validate('en-US'); // true
validate('en_US'); // false