form validator

Validate.js

会有一股神秘感。 提交于 2020-08-17 07:58:53
来源: http://rickharrison.github.com/validate.js/ Lightweight JavaScript form validation library inspired by CodeIgniter. No dependencies, just over 1kb gzipped, and customizable! validate.js (development - 10.5kb) validate.min.js (minified - 1.3kb) Example All of the fields were successfully validated! The required field is required. The password field is required. The password confirmation field is required. The terms of service field is required. Required field: Alphanumeric field: Password: Password Confirmation (match password): Email: Min length field (min. 8 chars): Required checkbox

gin form validator

坚强是说给别人听的谎言 提交于 2020-08-07 06:17:18
validator.go 封装一个统一处理验证消息的文件 package goo import ( "fmt" "github.com/go-playground/validator" "strings" ) func ValidationMessage(err error, msgs map[string]string) string { for _, i := range err.(validator.ValidationErrors) { key := fmt.Sprintf("%s_%s", strings.ToLower(i.Field()), strings.ToLower(i.Tag())) if msg, ok := msgs[key]; ok { return msg } msg := fmt.Sprintf("%s %s", i.Field(), i.Tag()) return msg } return err.Error() } address.go 这是一个使用demo type AddressDelete struct { Id int64 `json:"id" binding:"required"` } func (this AddressDelete) DoHandle(c *gin.Context) { if err := c.ShouldBind(