Example #1
0
func (s *ValidateTestSuite) TestCountryCodeExists() {
	for _, cs := range validCases {
		code := extractCountryCode(cs.Iban)
		exists := country.Exists(code)
		s.True(exists, "IBAN = %s", cs.Iban)
	}
}
Example #2
0
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
}
Example #3
0
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
}