Merge pull request #197 from go-playground/v8-development

V8 development
pull/200/head v8.5
Dean Karn 9 years ago
commit d5305abfab
  1. 409
      baked_in.go
  2. 2
      validator.go

@ -22,118 +22,134 @@ var bakedInAliasValidators = map[string]string{
// you can add, remove or even replace items to suite your needs, // you can add, remove or even replace items to suite your needs,
// or even disregard and use your own map if so desired. // or even disregard and use your own map if so desired.
var bakedInValidators = map[string]Func{ var bakedInValidators = map[string]Func{
"required": hasValue, "required": HasValue,
"len": hasLengthOf, "len": HasLengthOf,
"min": hasMinOf, "min": HasMinOf,
"max": hasMaxOf, "max": HasMaxOf,
"eq": isEq, "eq": IsEq,
"ne": isNe, "ne": IsNe,
"lt": isLt, "lt": IsLt,
"lte": isLte, "lte": IsLte,
"gt": isGt, "gt": IsGt,
"gte": isGte, "gte": IsGte,
"eqfield": isEqField, "eqfield": IsEqField,
"eqcsfield": isEqCrossStructField, "eqcsfield": IsEqCrossStructField,
"necsfield": isNeCrossStructField, "necsfield": IsNeCrossStructField,
"gtcsfield": isGtCrossStructField, "gtcsfield": IsGtCrossStructField,
"gtecsfield": isGteCrossStructField, "gtecsfield": IsGteCrossStructField,
"ltcsfield": isLtCrossStructField, "ltcsfield": IsLtCrossStructField,
"ltecsfield": isLteCrossStructField, "ltecsfield": IsLteCrossStructField,
"nefield": isNeField, "nefield": IsNeField,
"gtefield": isGteField, "gtefield": IsGteField,
"gtfield": isGtField, "gtfield": IsGtField,
"ltefield": isLteField, "ltefield": IsLteField,
"ltfield": isLtField, "ltfield": IsLtField,
"alpha": isAlpha, "alpha": IsAlpha,
"alphanum": isAlphanum, "alphanum": IsAlphanum,
"numeric": isNumeric, "numeric": IsNumeric,
"number": isNumber, "number": IsNumber,
"hexadecimal": isHexadecimal, "hexadecimal": IsHexadecimal,
"hexcolor": isHexcolor, "hexcolor": IsHEXColor,
"rgb": isRgb, "rgb": IsRGB,
"rgba": isRgba, "rgba": IsRGBA,
"hsl": isHsl, "hsl": IsHSL,
"hsla": isHsla, "hsla": IsHSLA,
"email": isEmail, "email": IsEmail,
"url": isURL, "url": IsURL,
"uri": isURI, "uri": IsURI,
"base64": isBase64, "base64": IsBase64,
"contains": contains, "contains": Contains,
"containsany": containsAny, "containsany": ContainsAny,
"containsrune": containsRune, "containsrune": ContainsRune,
"excludes": excludes, "excludes": Excludes,
"excludesall": excludesAll, "excludesall": ExcludesAll,
"excludesrune": excludesRune, "excludesrune": ExcludesRune,
"isbn": isISBN, "isbn": IsISBN,
"isbn10": isISBN10, "isbn10": IsISBN10,
"isbn13": isISBN13, "isbn13": IsISBN13,
"uuid": isUUID, "uuid": IsUUID,
"uuid3": isUUID3, "uuid3": IsUUID3,
"uuid4": isUUID4, "uuid4": IsUUID4,
"uuid5": isUUID5, "uuid5": IsUUID5,
"ascii": isASCII, "ascii": IsASCII,
"printascii": isPrintableASCII, "printascii": IsPrintableASCII,
"multibyte": hasMultiByteCharacter, "multibyte": HasMultiByteCharacter,
"datauri": isDataURI, "datauri": IsDataURI,
"latitude": isLatitude, "latitude": IsLatitude,
"longitude": isLongitude, "longitude": IsLongitude,
"ssn": isSSN, "ssn": IsSSN,
"ipv4": isIPv4, "ipv4": IsIPv4,
"ipv6": isIPv6, "ipv6": IsIPv6,
"ip": isIP, "ip": IsIP,
"cidrv4": isCIDRv4, "cidrv4": IsCIDRv4,
"cidrv6": isCIDRv6, "cidrv6": IsCIDRv6,
"cidr": isCIDR, "cidr": IsCIDR,
"mac": isMac, "mac": IsMAC,
} }
func isMac(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsMAC is the validation function for validating if the field's value is a valid MAC address.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsMAC(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
_, err := net.ParseMAC(field.String()) _, err := net.ParseMAC(field.String())
return err == nil return err == nil
} }
func isCIDRv4(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsCIDRv4 is the validation function for validating if the field's value is a valid v4 CIDR address.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsCIDRv4(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
ip, _, err := net.ParseCIDR(field.String()) ip, _, err := net.ParseCIDR(field.String())
return err == nil && ip.To4() != nil return err == nil && ip.To4() != nil
} }
func isCIDRv6(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsCIDRv6 is the validation function for validating if the field's value is a valid v6 CIDR address.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsCIDRv6(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
ip, _, err := net.ParseCIDR(field.String()) ip, _, err := net.ParseCIDR(field.String())
return err == nil && ip.To4() == nil return err == nil && ip.To4() == nil
} }
func isCIDR(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsCIDR is the validation function for validating if the field's value is a valid v4 or v6 CIDR address.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsCIDR(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
_, _, err := net.ParseCIDR(field.String()) _, _, err := net.ParseCIDR(field.String())
return err == nil return err == nil
} }
func isIPv4(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsIPv4 is the validation function for validating if a value is a valid v4 IP address.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsIPv4(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
ip := net.ParseIP(field.String()) ip := net.ParseIP(field.String())
return ip != nil && ip.To4() != nil return ip != nil && ip.To4() != nil
} }
func isIPv6(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsIPv6 is the validation function for validating if the field's value is a valid v6 IP address.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsIPv6(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
ip := net.ParseIP(field.String()) ip := net.ParseIP(field.String())
return ip != nil && ip.To4() == nil return ip != nil && ip.To4() == nil
} }
func isIP(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsIP is the validation function for validating if the field's value is a valid v4 or v6 IP address.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsIP(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
ip := net.ParseIP(field.String()) ip := net.ParseIP(field.String())
return ip != nil return ip != nil
} }
func isSSN(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsSSN is the validation function for validating if the field's value is a valid SSN.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsSSN(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
if field.Len() != 11 { if field.Len() != 11 {
return false return false
@ -142,15 +158,21 @@ func isSSN(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Va
return sSNRegex.MatchString(field.String()) return sSNRegex.MatchString(field.String())
} }
func isLongitude(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsLongitude is the validation function for validating if the field's value is a valid longitude coordinate.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsLongitude(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return longitudeRegex.MatchString(field.String()) return longitudeRegex.MatchString(field.String())
} }
func isLatitude(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsLatitude is the validation function for validating if the field's value is a valid latitude coordinate.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsLatitude(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return latitudeRegex.MatchString(field.String()) return latitudeRegex.MatchString(field.String())
} }
func isDataURI(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsDataURI is the validation function for validating if the field's value is a valid data URI.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsDataURI(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
uri := strings.SplitN(field.String(), ",", 2) uri := strings.SplitN(field.String(), ",", 2)
@ -164,10 +186,12 @@ func isDataURI(v *Validate, topStruct reflect.Value, currentStructOrField reflec
fld := reflect.ValueOf(uri[1]) fld := reflect.ValueOf(uri[1])
return isBase64(v, topStruct, currentStructOrField, fld, fld.Type(), fld.Kind(), param) return IsBase64(v, topStruct, currentStructOrField, fld, fld.Type(), fld.Kind(), param)
} }
func hasMultiByteCharacter(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // HasMultiByteCharacter is the validation function for validating if the field's value has a multi byte character.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func HasMultiByteCharacter(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
if field.Len() == 0 { if field.Len() == 0 {
return true return true
@ -176,35 +200,51 @@ func hasMultiByteCharacter(v *Validate, topStruct reflect.Value, currentStructOr
return multibyteRegex.MatchString(field.String()) return multibyteRegex.MatchString(field.String())
} }
func isPrintableASCII(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsPrintableASCII is the validation function for validating if the field's value is a valid printable ASCII character.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsPrintableASCII(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return printableASCIIRegex.MatchString(field.String()) return printableASCIIRegex.MatchString(field.String())
} }
func isASCII(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsASCII is the validation function for validating if the field's value is a valid ASCII character.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsASCII(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return aSCIIRegex.MatchString(field.String()) return aSCIIRegex.MatchString(field.String())
} }
func isUUID5(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsUUID5 is the validation function for validating if the field's value is a valid v5 UUID.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsUUID5(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return uUID5Regex.MatchString(field.String()) return uUID5Regex.MatchString(field.String())
} }
func isUUID4(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsUUID4 is the validation function for validating if the field's value is a valid v4 UUID.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsUUID4(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return uUID4Regex.MatchString(field.String()) return uUID4Regex.MatchString(field.String())
} }
func isUUID3(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsUUID3 is the validation function for validating if the field's value is a valid v3 UUID.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsUUID3(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return uUID3Regex.MatchString(field.String()) return uUID3Regex.MatchString(field.String())
} }
func isUUID(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsUUID is the validation function for validating if the field's value is a valid UUID of any version.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsUUID(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return uUIDRegex.MatchString(field.String()) return uUIDRegex.MatchString(field.String())
} }
func isISBN(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsISBN is the validation function for validating if the field's value is a valid v10 or v13 ISBN.
return isISBN10(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param) || isISBN13(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param) // NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsISBN(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return IsISBN10(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param) || IsISBN13(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param)
} }
func isISBN13(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsISBN13 is the validation function for validating if the field's value is a valid v13 ISBN.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsISBN13(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
s := strings.Replace(strings.Replace(field.String(), "-", "", 4), " ", "", 4) s := strings.Replace(strings.Replace(field.String(), "-", "", 4), " ", "", 4)
@ -228,7 +268,9 @@ func isISBN13(v *Validate, topStruct reflect.Value, currentStructOrField reflect
return false return false
} }
func isISBN10(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsISBN10 is the validation function for validating if the field's value is a valid v10 ISBN.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsISBN10(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
s := strings.Replace(strings.Replace(field.String(), "-", "", 3), " ", "", 3) s := strings.Replace(strings.Replace(field.String(), "-", "", 3), " ", "", 3)
@ -256,33 +298,47 @@ func isISBN10(v *Validate, topStruct reflect.Value, currentStructOrField reflect
return false return false
} }
func excludesRune(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // ExcludesRune is the validation function for validating that the field's value does not contain the rune specified withing the param.
return !containsRune(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param) // NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func ExcludesRune(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return !ContainsRune(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param)
} }
func excludesAll(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // ExcludesAll is the validation function for validating that the field's value does not contain any of the characters specified withing the param.
return !containsAny(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param) // NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func ExcludesAll(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return !ContainsAny(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param)
} }
func excludes(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // Excludes is the validation function for validating that the field's value does not contain the text specified withing the param.
return !contains(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param) // NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func Excludes(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return !Contains(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param)
} }
func containsRune(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // ContainsRune is the validation function for validating that the field's value contains the rune specified withing the param.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func ContainsRune(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
r, _ := utf8.DecodeRuneInString(param) r, _ := utf8.DecodeRuneInString(param)
return strings.ContainsRune(field.String(), r) return strings.ContainsRune(field.String(), r)
} }
func containsAny(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // ContainsAny is the validation function for validating that the field's value contains any of the characters specified withing the param.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func ContainsAny(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return strings.ContainsAny(field.String(), param) return strings.ContainsAny(field.String(), param)
} }
func contains(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // Contains is the validation function for validating that the field's value contains the text specified withing the param.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func Contains(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return strings.Contains(field.String(), param) return strings.Contains(field.String(), param)
} }
func isNeField(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsNeField is the validation function for validating if the current field's value is not equal to the field specified by the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsNeField(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
currentField, currentKind, ok := v.GetStructFieldOK(currentStructOrField, param) currentField, currentKind, ok := v.GetStructFieldOK(currentStructOrField, param)
@ -325,11 +381,15 @@ func isNeField(v *Validate, topStruct reflect.Value, currentStructOrField reflec
return field.String() != currentField.String() return field.String() != currentField.String()
} }
func isNe(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsNe is the validation function for validating that the field's value does not equal the provided param value.
return !isEq(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param) // NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsNe(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return !IsEq(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param)
} }
func isLteCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsLteCrossStructField is the validation function for validating if the current field's value is less than or equal to the field, within a separate struct, specified by the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsLteCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
topField, topKind, ok := v.GetStructFieldOK(topStruct, param) topField, topKind, ok := v.GetStructFieldOK(topStruct, param)
if !ok || topKind != fieldKind { if !ok || topKind != fieldKind {
@ -370,7 +430,9 @@ func isLteCrossStructField(v *Validate, topStruct reflect.Value, current reflect
return field.String() <= topField.String() return field.String() <= topField.String()
} }
func isLtCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsLtCrossStructField is the validation function for validating if the current field's value is less than the field, within a separate struct, specified by the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsLtCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
topField, topKind, ok := v.GetStructFieldOK(topStruct, param) topField, topKind, ok := v.GetStructFieldOK(topStruct, param)
if !ok || topKind != fieldKind { if !ok || topKind != fieldKind {
@ -411,7 +473,9 @@ func isLtCrossStructField(v *Validate, topStruct reflect.Value, current reflect.
return field.String() < topField.String() return field.String() < topField.String()
} }
func isGteCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsGteCrossStructField is the validation function for validating if the current field's value is greater than or equal to the field, within a separate struct, specified by the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsGteCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
topField, topKind, ok := v.GetStructFieldOK(topStruct, param) topField, topKind, ok := v.GetStructFieldOK(topStruct, param)
if !ok || topKind != fieldKind { if !ok || topKind != fieldKind {
@ -452,7 +516,9 @@ func isGteCrossStructField(v *Validate, topStruct reflect.Value, current reflect
return field.String() >= topField.String() return field.String() >= topField.String()
} }
func isGtCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsGtCrossStructField is the validation function for validating if the current field's value is greater than the field, within a separate struct, specified by the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsGtCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
topField, topKind, ok := v.GetStructFieldOK(topStruct, param) topField, topKind, ok := v.GetStructFieldOK(topStruct, param)
if !ok || topKind != fieldKind { if !ok || topKind != fieldKind {
@ -493,7 +559,9 @@ func isGtCrossStructField(v *Validate, topStruct reflect.Value, current reflect.
return field.String() > topField.String() return field.String() > topField.String()
} }
func isNeCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsNeCrossStructField is the validation function for validating that the current field's value is not equal to the field, within a separate struct, specified by the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsNeCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
topField, currentKind, ok := v.GetStructFieldOK(topStruct, param) topField, currentKind, ok := v.GetStructFieldOK(topStruct, param)
if !ok || currentKind != fieldKind { if !ok || currentKind != fieldKind {
@ -534,7 +602,9 @@ func isNeCrossStructField(v *Validate, topStruct reflect.Value, current reflect.
return topField.String() != field.String() return topField.String() != field.String()
} }
func isEqCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsEqCrossStructField is the validation function for validating that the current field's value is equal to the field, within a separate struct, specified by the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsEqCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
topField, topKind, ok := v.GetStructFieldOK(topStruct, param) topField, topKind, ok := v.GetStructFieldOK(topStruct, param)
if !ok || topKind != fieldKind { if !ok || topKind != fieldKind {
@ -575,7 +645,9 @@ func isEqCrossStructField(v *Validate, topStruct reflect.Value, current reflect.
return topField.String() == field.String() return topField.String() == field.String()
} }
func isEqField(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsEqField is the validation function for validating if the current field's value is equal to the field specified by the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsEqField(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
currentField, currentKind, ok := v.GetStructFieldOK(currentStructOrField, param) currentField, currentKind, ok := v.GetStructFieldOK(currentStructOrField, param)
if !ok || currentKind != fieldKind { if !ok || currentKind != fieldKind {
@ -617,7 +689,9 @@ func isEqField(v *Validate, topStruct reflect.Value, currentStructOrField reflec
return field.String() == currentField.String() return field.String() == currentField.String()
} }
func isEq(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsEq is the validation function for validating if the current field's value is equal to the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsEq(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
switch fieldKind { switch fieldKind {
@ -648,11 +722,15 @@ func isEq(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Val
panic(fmt.Sprintf("Bad field type %T", field.Interface())) panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} }
func isBase64(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsBase64 is the validation function for validating if the current field's value is a valid base 64.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsBase64(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return base64Regex.MatchString(field.String()) return base64Regex.MatchString(field.String())
} }
func isURI(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsURI is the validation function for validating if the current field's value is a valid URI.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsURI(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
switch fieldKind { switch fieldKind {
@ -665,7 +743,9 @@ func isURI(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Va
panic(fmt.Sprintf("Bad field type %T", field.Interface())) panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} }
func isURL(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsURL is the validation function for validating if the current field's value is a valid URL.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsURL(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
switch fieldKind { switch fieldKind {
@ -686,51 +766,75 @@ func isURL(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Va
panic(fmt.Sprintf("Bad field type %T", field.Interface())) panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} }
func isEmail(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsEmail is the validation function for validating if the current field's value is a valid email address.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsEmail(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return emailRegex.MatchString(field.String()) return emailRegex.MatchString(field.String())
} }
func isHsla(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsHSLA is the validation function for validating if the current field's value is a valid HSLA color.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsHSLA(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return hslaRegex.MatchString(field.String()) return hslaRegex.MatchString(field.String())
} }
func isHsl(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsHSL is the validation function for validating if the current field's value is a valid HSL color.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsHSL(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return hslRegex.MatchString(field.String()) return hslRegex.MatchString(field.String())
} }
func isRgba(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsRGBA is the validation function for validating if the current field's value is a valid RGBA color.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsRGBA(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return rgbaRegex.MatchString(field.String()) return rgbaRegex.MatchString(field.String())
} }
func isRgb(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsRGB is the validation function for validating if the current field's value is a valid RGB color.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsRGB(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return rgbRegex.MatchString(field.String()) return rgbRegex.MatchString(field.String())
} }
func isHexcolor(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsHEXColor is the validation function for validating if the current field's value is a valid HEX color.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsHEXColor(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return hexcolorRegex.MatchString(field.String()) return hexcolorRegex.MatchString(field.String())
} }
func isHexadecimal(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsHexadecimal is the validation function for validating if the current field's value is a valid hexadecimal.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsHexadecimal(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return hexadecimalRegex.MatchString(field.String()) return hexadecimalRegex.MatchString(field.String())
} }
func isNumber(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsNumber is the validation function for validating if the current field's value is a valid number.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsNumber(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return numberRegex.MatchString(field.String()) return numberRegex.MatchString(field.String())
} }
func isNumeric(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsNumeric is the validation function for validating if the current field's value is a valid numeric value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsNumeric(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return numericRegex.MatchString(field.String()) return numericRegex.MatchString(field.String())
} }
func isAlphanum(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsAlphanum is the validation function for validating if the current field's value is a valid alphanumeric value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsAlphanum(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return alphaNumericRegex.MatchString(field.String()) return alphaNumericRegex.MatchString(field.String())
} }
func isAlpha(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsAlpha is the validation function for validating if the current field's value is a valid alpha value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsAlpha(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return alphaRegex.MatchString(field.String()) return alphaRegex.MatchString(field.String())
} }
func hasValue(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // HasValue is the validation function for validating if the current field's value is not the default static value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func HasValue(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
switch fieldKind { switch fieldKind {
case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func: case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func:
@ -740,7 +844,9 @@ func hasValue(v *Validate, topStruct reflect.Value, currentStructOrField reflect
} }
} }
func isGteField(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsGteField is the validation function for validating if the current field's value is greater than or equal to the field specified by the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsGteField(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
currentField, currentKind, ok := v.GetStructFieldOK(currentStructOrField, param) currentField, currentKind, ok := v.GetStructFieldOK(currentStructOrField, param)
if !ok || currentKind != fieldKind { if !ok || currentKind != fieldKind {
@ -781,7 +887,9 @@ func isGteField(v *Validate, topStruct reflect.Value, currentStructOrField refle
return len(field.String()) >= len(currentField.String()) return len(field.String()) >= len(currentField.String())
} }
func isGtField(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsGtField is the validation function for validating if the current field's value is greater than the field specified by the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsGtField(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
currentField, currentKind, ok := v.GetStructFieldOK(currentStructOrField, param) currentField, currentKind, ok := v.GetStructFieldOK(currentStructOrField, param)
if !ok || currentKind != fieldKind { if !ok || currentKind != fieldKind {
@ -822,7 +930,9 @@ func isGtField(v *Validate, topStruct reflect.Value, currentStructOrField reflec
return len(field.String()) > len(currentField.String()) return len(field.String()) > len(currentField.String())
} }
func isGte(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsGte is the validation function for validating if the current field's value is greater than or equal to the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsGte(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
switch fieldKind { switch fieldKind {
@ -865,7 +975,9 @@ func isGte(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Va
panic(fmt.Sprintf("Bad field type %T", field.Interface())) panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} }
func isGt(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsGt is the validation function for validating if the current field's value is greater than the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsGt(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
switch fieldKind { switch fieldKind {
@ -904,10 +1016,9 @@ func isGt(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Val
panic(fmt.Sprintf("Bad field type %T", field.Interface())) panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} }
// length tests whether a variable's length is equal to a given // HasLengthOf is the validation function for validating if the current field's value is equal to the param's value.
// value. For strings it tests the number of characters whereas // NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
// for maps and slices it tests the number of items. func HasLengthOf(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
func hasLengthOf(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
switch fieldKind { switch fieldKind {
@ -940,16 +1051,16 @@ func hasLengthOf(v *Validate, topStruct reflect.Value, currentStructOrField refl
panic(fmt.Sprintf("Bad field type %T", field.Interface())) panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} }
// min tests whether a variable value is larger or equal to a given // HasMinOf is the validation function for validating if the current field's value is greater than or equal to the param's value.
// number. For number types, it's a simple lesser-than test; for // NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
// strings it tests the number of characters whereas for maps func HasMinOf(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
// and slices it tests the number of items.
func hasMinOf(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return isGte(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param) return IsGte(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param)
} }
func isLteField(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsLteField is the validation function for validating if the current field's value is less than or equal to the field specified by the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsLteField(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
currentField, currentKind, ok := v.GetStructFieldOK(currentStructOrField, param) currentField, currentKind, ok := v.GetStructFieldOK(currentStructOrField, param)
if !ok || currentKind != fieldKind { if !ok || currentKind != fieldKind {
@ -990,7 +1101,9 @@ func isLteField(v *Validate, topStruct reflect.Value, currentStructOrField refle
return len(field.String()) <= len(currentField.String()) return len(field.String()) <= len(currentField.String())
} }
func isLtField(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsLtField is the validation function for validating if the current field's value is less than the field specified by the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsLtField(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
currentField, currentKind, ok := v.GetStructFieldOK(currentStructOrField, param) currentField, currentKind, ok := v.GetStructFieldOK(currentStructOrField, param)
if !ok || currentKind != fieldKind { if !ok || currentKind != fieldKind {
@ -1031,7 +1144,9 @@ func isLtField(v *Validate, topStruct reflect.Value, currentStructOrField reflec
return len(field.String()) < len(currentField.String()) return len(field.String()) < len(currentField.String())
} }
func isLte(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsLte is the validation function for validating if the current field's value is less than or equal to the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsLte(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
switch fieldKind { switch fieldKind {
@ -1074,7 +1189,9 @@ func isLte(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Va
panic(fmt.Sprintf("Bad field type %T", field.Interface())) panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} }
func isLt(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { // IsLt is the validation function for validating if the current field's value is less than the param's value.
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
func IsLt(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
switch fieldKind { switch fieldKind {
@ -1114,10 +1231,8 @@ func isLt(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Val
panic(fmt.Sprintf("Bad field type %T", field.Interface())) panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} }
// max tests whether a variable value is lesser than a given // HasMaxOf is the validation function for validating if the current field's value is less than or equal to the param's value.
// value. For numbers, it's a simple lesser-than test; for // NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
// strings it tests the number of characters whereas for maps func HasMaxOf(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
// and slices it tests the number of items. return IsLte(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param)
func hasMaxOf(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
return isLte(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param)
} }

@ -532,7 +532,7 @@ func (v *Validate) traverseField(topStruct reflect.Value, currentStruct reflect.
if valTag.tagVals[0][0] == omitempty { if valTag.tagVals[0][0] == omitempty {
if !hasValue(v, topStruct, currentStruct, current, typ, kind, blank) { if !HasValue(v, topStruct, currentStruct, current, typ, kind, blank) {
return return
} }
continue continue

Loading…
Cancel
Save