Skip to content

Commit

Permalink
Merge pull request #14 from GeertJohan/patch-1
Browse files Browse the repository at this point in the history
Export ErrCountryNotFound
  • Loading branch information
dannyvankooten authored Nov 7, 2023
2 parents 7af910a + cb1417a commit 2a35151
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const serviceURL = "http://ec.europa.eu/taxation_customs/vies/services/checkVatS
// ErrInvalidVATNumber will be returned when an invalid VAT number is passed to a function that validates existence.
var ErrInvalidVATNumber = errors.New("vat: vat number is invalid")

// ErrCountryNotFound indicates that this package could not find a country matching the VAT number prefix.
var ErrCountryNotFound = errors.New("vat: country not found")

// ValidateNumber validates a VAT number by both format and existence.
// The existence check uses the VIES VAT validation SOAP API and will only run when format validation passes.
func ValidateNumber(n string) (bool, error) {
Expand Down Expand Up @@ -77,10 +80,9 @@ func ValidateNumberFormat(n string) (bool, error) {
}

n = strings.ToUpper(n)
var CountryNotFound = errors.New("CountryNotFound")
pattern, ok := patterns[n[0:2]]
if !ok {
return false, CountryNotFound
return false, ErrCountryNotFound
}

matched, err := regexp.MatchString(pattern, n[2:])
Expand Down

0 comments on commit 2a35151

Please sign in to comment.