MCPcopy
hub / github.com/go-playground/validator / fieldMatchesRegexByStringerValOrString

Function fieldMatchesRegexByStringerValOrString

util.go:323–335  ·  view source on GitHub ↗

Checks if field value matches regex. If fl.Field can be cast to Stringer, it uses the Stringer interfaces String() return value. Otherwise, it uses fl.Field's String() value.

(regexFn func() *regexp.Regexp, fl FieldLevel)

Source from the content-addressed store, hash-verified

321// Checks if field value matches regex. If fl.Field can be cast to Stringer, it uses the Stringer interfaces
322// String() return value. Otherwise, it uses fl.Field's String() value.
323func fieldMatchesRegexByStringerValOrString(regexFn func() *regexp.Regexp, fl FieldLevel) bool {
324 regex := regexFn()
325 switch fl.Field().Kind() {
326 case reflect.String:
327 return regex.MatchString(fl.Field().String())
328 default:
329 if stringer, ok := getValue(fl.Field()).(fmt.Stringer); ok {
330 return regex.MatchString(stringer.String())
331 } else {
332 return regex.MatchString(fl.Field().String())
333 }
334 }
335}

Callers 9

isUUID5Function · 0.85
isUUID4Function · 0.85
isUUID3Function · 0.85
isUUIDFunction · 0.85
isUUID5RFC4122Function · 0.85
isUUID4RFC4122Function · 0.85
isUUID3RFC4122Function · 0.85
isUUIDRFC4122Function · 0.85
isULIDFunction · 0.85

Calls 4

getValueFunction · 0.85
KindMethod · 0.65
FieldMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…