2 回答
TA贡献1876条经验 获得超6个赞
也许这可以帮助?这是我为我的 ISO8601 格式日期时间所做的
CreatedAt string `json:"created_at" validate:"ISO8601date"
func IsISO8601Date(fl validator.FieldLevel) bool {
ISO8601DateRegexString := "^(?:[1-9]\\d{3}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1\\d|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[1-9]\\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)-02-29)T(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d{1,9})?(?:Z|[+-][01]\\d:[0-5]\\d)$"
ISO8601DateRegex := regexp.MustCompile(ISO8601DateRegexString)
return ISO8601DateRegex.MatchString(fl.Field().String())
}
validate = validator.New()
_ = validate.RegisterValidation("ISO8601date", IsISO8601Date)
- 2 回答
- 0 关注
- 93 浏览
添加回答
举报