func (s *ValidateTestSuite) TestCountryCodeExists() { for _, cs := range validCases { code := extractCountryCode(cs.Iban) exists := country.Exists(code) s.True(exists, "IBAN = %s", cs.Iban) } }
func validateCountryCode(value string) error { code := extractCountryCode(value) match, _ := regexp.MatchString("^[A-Z]+$", code) if !match { return ErrInvalidCountryCode } exists := country.Exists(code) if !exists { return ErrCountryCodeNotPresent } return nil }
func validateCountryCode(value string) (string, error) { code := extractCountryCode(value) if code != strings.ToUpper(code) { return "", ErrCountryCodeNotUpper } match, _ := regexp.MatchString("^[A-Z]+$", code) if !match { return "", ErrCountryCodeNotAlpha } exists := country.Exists(code) if !exists { return "", ErrCountryCodeNotPresent } return code, nil }