package util import ( "regexp" "github.com/go-playground/validator/v10" ) var Validator *validator.Validate func init() { Validator = validator.New() _ = Validator.RegisterValidation("validregexp", isValidRegExp) } func isValidRegExp(fl validator.FieldLevel) bool { expr := fl.Field().String() if expr == "" { return true } _, err := regexp.Compile(expr) return err == nil }