Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( PhoneValidate = NewValidator("phoneValidate", func(fl validator.FieldLevel) bool { ok, _ := regexp.MatchString(`^1[3-9][0-9]{9}$`, fl.Field().String()) return ok }, func(v Validation) validator.RegisterTranslationsFunc { return func(ut ut.Translator) error { return ut.Add(v.Tag(), "{0}不是一个合法的手机号", true) } }, func(v Validation) validator.TranslationFunc { return func(ut ut.Translator, fe validator.FieldError) string { t, _ := ut.T(v.Tag(), fe.Field()) return t } }) EmailValidate = NewValidator("emailValidate", func(fl validator.FieldLevel) bool { ok, _ := regexp.MatchString(`^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$`, fl.Field().String()) return ok }, func(v Validation) validator.RegisterTranslationsFunc { return func(ut ut.Translator) error { return ut.Add(v.Tag(), "{0}不是一个合法的邮箱", true) } }, func(v Validation) validator.TranslationFunc { return func(ut ut.Translator, fe validator.FieldError) string { t, _ := ut.T(v.Tag(), fe.Field()) return t } }) )
Functions ¶
func GetDefaultValidator ¶ added in v1.5.2
func GetDefaultValidator() *validator.Validate
func GetTranslator ¶
func GetTranslator() ut.Translator
func LoadValidation ¶ added in v1.5.2
func LoadValidation(valids []Validation)
func ValidatorTranslate ¶
Types ¶
type Validation ¶
type Validation interface { Tag() string Validator() validator.Func RegisterTranslation() validator.RegisterTranslationsFunc Translation() validator.TranslationFunc }
func NewValidator ¶
func NewValidator(tag string, validFunc validator.Func, regTranFunc func(Validation) validator.RegisterTranslationsFunc, tranFunc func(Validation) validator.TranslationFunc, ) Validation
Click to show internal directories.
Click to hide internal directories.