...
1 package validators
2
3 import (
4 "reflect"
5 "strings"
6
7 "github.com/go-playground/validator/v10"
8 )
9
10
11
12 func NotBlank(fl validator.FieldLevel) bool {
13 field := fl.Field()
14
15 switch field.Kind() {
16 case reflect.String:
17 return len(strings.Trim(strings.TrimSpace(field.String()), "\x1c\x1d\x1e\x1f")) > 0
18 case reflect.Chan, reflect.Map, reflect.Slice, reflect.Array:
19 return field.Len() > 0
20 case reflect.Ptr, reflect.Interface, reflect.Func:
21 return !field.IsNil()
22 default:
23 return field.IsValid() && field.Interface() != reflect.Zero(field.Type()).Interface()
24 }
25 }
26
View as plain text