Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
fix iso code validation (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehelmick authored Sep 26, 2020
1 parent 7742d50 commit ff11429
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cmd/server/assets/admin/realms/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ <h1>New realm</h1>
{{template "errorable" $realm.ErrorsFor "regionCode"}}
<small class="form-text text-muted">
Used in creating deep link SMS for multi-helath authority apps. Region should
be <a href="https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes">ISO 3166-1 country codes and ISO 3166-2 subdivision codes</a> where applicable.
For example, Washington State would be <code>US-WA</code>.
be <a href="https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes">ISO 3166-1 country codes and (optionally) ISO 3166-2 subdivision codes</a> where applicable.
For example, Washington State would be <code>US-WA</code>, and Canada would be <code>CA</code>. The region code should be scoped to the authority of the public health
system represented by this verification system.
</small>
</div>

Expand Down
6 changes: 4 additions & 2 deletions pkg/database/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,10 @@ func (r *Realm) BeforeSave(tx *gorm.DB) error {
r.AddError("regionCode", "cannot be blank when using EN Express")
} else {
parts := strings.Split(r.RegionCode, "-")
if len(parts) != 2 {
r.AddError("regionCode", "must be formated like 'region-subregion', 2 characters dash 2 or 3 characters")
if lp := len(parts); lp != 2 {
if lp == 1 && len(parts[0]) != 2 {
r.AddError("regionCode", "must be formated like 'region' (2 characters) or 'region-subregion' (2 characters dash 2 or 3 characters)")
}
} else {
if len(parts[0]) != 2 {
r.AddError("regionCode", "first part must be exactly 2 characters in length")
Expand Down

0 comments on commit ff11429

Please sign in to comment.