2021-10-27 00:27:29 +08:00
|
|
|
package validation
|
2021-07-25 04:13:24 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
|
)
|
|
|
|
|
2021-10-09 03:07:12 +08:00
|
|
|
// CheckYesOrNo - checks if a field on a struct is yes or no
|
2021-07-25 04:13:24 +08:00
|
|
|
func CheckYesOrNo(fl validator.FieldLevel) bool {
|
|
|
|
return fl.Field().String() == "yes" || fl.Field().String() == "no"
|
|
|
|
}
|
|
|
|
|
2021-10-09 03:07:12 +08:00
|
|
|
// CheckRegex - check if a struct's field passes regex test
|
2021-07-25 04:13:24 +08:00
|
|
|
func CheckRegex(fl validator.FieldLevel) bool {
|
|
|
|
re := regexp.MustCompile(fl.Param())
|
|
|
|
return re.MatchString(fl.Field().String())
|
|
|
|
}
|