1 // Copyright 2014 John G. Beckett. All rights reserved.
2 // Use of this source code is governed by the MIT
3 // license that can be found in the LICENSE file.
5 // Package langreg is a library for validating ISO 639-1 language
6 // and ISO 1366-1_alpa-2 region codes.
8 // ISO 639-1 language codes are two charcters long and use only lowercase ASCII
9 // character a-z. E.g.:
13 // ISO 1366-1_alpa-2 region codes are two charcters long and use only uppercase
14 // ASCII character A-Z. E.g.:
18 // When combined as a composite language and region code, they are concatented
19 // with an underscore. E.g.:
21 // "en_US", "en_ZA", "fr_FR"
23 // Any codes not meeting these formatting requirement will fail validation.
26 // IsValidLangRegCode returns true if the string s is a valid ISO 639-1 language
27 // and ISO1366-1_alpa-2 region code separated by an underscore. E.g. "en_US".
28 func IsValidLangRegCode(s string) bool {
30 // all valid codes are 5 characters long
35 // the middle (third) character must be a '_' char
40 // check the language code, which should be the first two characters in s
41 if !IsValidLanguageCode(s[:2]) {
45 // check the region code, which should be the last two characters in s
46 if !IsValidRegionCode(s[3:]) {