示例#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)
	}
}
示例#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
}
示例#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
}