-
Notifications
You must be signed in to change notification settings - Fork 116
邮箱验证失败 #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
结构体tag试试 |
现在是可以了。但又有个新问题。验证失败时,为什么没有显示我自定义的消息。而是默认的英文消息(email value is invalid mail)。package main
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/gookit/goutil/dump"
"github.com/gookit/validate"
)
func main() {
binding.Validator = &customValidator{}
r := gin.Default()
r.POST("/user/list", func(ctx *gin.Context) {
var user User
err := ctx.ShouldBindJSON(&user)
if err != nil {
dump.P(err)
ctx.String(400, "出错"+err.Error())
return
}
ctx.String(200, "验证通过!")
})
r.Run(":8080")
}
type User struct {
Email string `json:"email" validate:"required|email" message:"required:eamil必填的信息|email:邮箱验证失败的信息"`
}
type customValidator struct{}
func (c *customValidator) ValidateStruct(ptr interface{}) error {
v := validate.Struct(ptr)
v.Validate() // do validating
if v.Errors.Empty() {
return nil
}
return v.Errors
}
func (c *customValidator) Engine() interface{} {
return nil
} |
提示消息这里有点问题,我开了一个新issue #160 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
用户邮箱地址是
xxxx.88@qq.com
时验证不通过包是否可以使用如下规则
^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$
The text was updated successfully, but these errors were encountered: