Skip to content

Commit

Permalink
Add iso-3166-2 (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
erma07 authored Jul 8, 2021
1 parent 8bfa88a commit af8b8d1
Show file tree
Hide file tree
Showing 3 changed files with 1,005 additions and 0 deletions.
7 changes: 7 additions & 0 deletions baked_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ var (
"iso3166_1_alpha2": isIso3166Alpha2,
"iso3166_1_alpha3": isIso3166Alpha3,
"iso3166_1_alpha_numeric": isIso3166AlphaNumeric,
"iso3166_2": isIso31662,
"bcp47_language_tag": isBCP47LanguageTag,
"postcode_iso3166_alpha2": isPostcodeByIso3166Alpha2,
"postcode_iso3166_alpha2_field": isPostcodeByIso3166Alpha2Field,
Expand Down Expand Up @@ -2345,6 +2346,12 @@ func isIso3166AlphaNumeric(fl FieldLevel) bool {
return iso3166_1_alpha_numeric[code]
}

// isIso31662 is the validation function for validating if the current field's value is a valid iso3166-2 code.
func isIso31662(fl FieldLevel) bool {
val := fl.Field().String()
return iso3166_2[val]
}

// isBCP47LanguageTag is the validation function for validating if the current field's value is a valid BCP 47 language tag, as parsed by language.Parse
func isBCP47LanguageTag(fl FieldLevel) bool {
field := fl.Field()
Expand Down
Loading

0 comments on commit af8b8d1

Please sign in to comment.