Validation
BCP 47 Language Tag
Validate BCP 47 language tags like `en`, `en-US`, `zh-Hant-TW`, or `pt-BR`.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
^[a-zA-Z]{2,3}(?:-[A-Za-z0-9]{2,8})*$Raw source: ^[a-zA-Z]{2,3}(?:-[A-Za-z0-9]{2,8})*$
How it works
^[a-zA-Z]{2,3} matches the primary 2- or 3-letter language subtag. (?:-[A-Za-z0-9]{2,8})* matches subsequent subtags (script, region, variant) joined with hyphens. Each subtag is 2–8 alphanumerics. This validates STRUCTURE — for spec-compliant validation use a real BCP 47 parser.
Examples
Input
enMatches
en
Input
zh-Hant-TWMatches
zh-Hant-TW
Input
ENGLISHNo match
—Common use cases
- •i18n routing in web frameworks
- •Accept-Language header validation
- •CMS locale config
- •Translation pipeline input filtering
Related patterns
MIME Type
ValidationValidate MIME media type strings like text/html, application/json, or image/png; charset=utf-8.
Cron Expression
ValidationValidate standard 5-field Unix cron expressions: minute, hour, day-of-month, month, day-of-week.
Cron Expression (Quartz/Spring, 6-Field)
ValidationValidate 6-field Quartz/Spring cron expressions including the seconds field at the front.
Email Address Validation
ValidationMatch and validate email addresses in the standard user@domain.tld format.