validation.go 459 B

123456789101112131415161718
  1. package validation
  2. import (
  3. "regexp"
  4. "github.com/go-playground/validator/v10"
  5. )
  6. // CheckYesOrNo - checks if a field on a struct is yes or no
  7. func CheckYesOrNo(fl validator.FieldLevel) bool {
  8. return fl.Field().String() == "yes" || fl.Field().String() == "no"
  9. }
  10. // CheckRegex - check if a struct's field passes regex test
  11. func CheckRegex(fl validator.FieldLevel) bool {
  12. re := regexp.MustCompile(fl.Param())
  13. return re.MatchString(fl.Field().String())
  14. }