本文整理汇总了Golang中github.com/robfig/revel.Validation.Errors方法的典型用法代码示例。如果您正苦于以下问题:Golang Validation.Errors方法的具体用法?Golang Validation.Errors怎么用?Golang Validation.Errors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/robfig/revel.Validation
的用法示例。
在下文中一共展示了Validation.Errors方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Validate
func (user *User) Validate(v *revel.Validation) {
v.Required(user.Name).Message("请输入用户名")
valid := v.Match(user.Name, nameRegex).Message("只能使用字母、数字和下划线")
if valid.Ok {
if user.HasName() {
err := &revel.ValidationError{
Message: "该用户名已经注册过",
Key: "user.Name",
}
valid.Error = err
valid.Ok = false
v.Errors = append(v.Errors, err)
}
}
v.Required(user.Email).Message("请输入Email")
valid = v.Email(user.Email).Message("无效的电子邮件")
if valid.Ok {
if user.HasEmail() {
err := &revel.ValidationError{
Message: "该邮件已经注册过",
Key: "user.Email",
}
valid.Error = err
valid.Ok = false
v.Errors = append(v.Errors, err)
}
}
v.Required(user.Password).Message("请输入密码")
v.MinSize(user.Password, 3).Message("密码最少三位")
v.Required(user.ConfirmPassword == user.Password).Message("密码不一致")
}
示例2: Validate
func (a *Admin) Validate(v *revel.Validation) {
v.Required(a.Username).Message("请输入用户名!")
valid := v.Match(a.Username, regexp.MustCompile("^\\w*$")).Message("只能使用字母、数字和下划线!")
if valid.Ok {
if a.HasName() {
err := &revel.ValidationError{
Message: "该用户名已经注册过!",
Key: "a.Username",
}
valid.Error = err
valid.Ok = false
v.Errors = append(v.Errors, err)
}
}
v.Required(a.Email).Message("请输入Email")
valid = v.Email(a.Email).Message("无效的电子邮件!")
if valid.Ok {
if a.HasEmail() {
err := &revel.ValidationError{
Message: "该邮件已经注册过!",
Key: "a.Email",
}
valid.Error = err
valid.Ok = false
v.Errors = append(v.Errors, err)
}
}
v.Required(a.Password).Message("请输入密码!")
v.MinSize(a.Password, 3).Message("密码最少三位!")
}
示例3: Validate
func (category Category) Validate(v *revel.Validation) {
v.Required(category.Name).Message("请输入名称")
if category.HasName() {
err := &revel.ValidationError{
Message: "名称已存在",
Key: "category.Name",
}
v.Errors = append(v.Errors, err)
}
}
示例4: checkImageExt
func checkImageExt(v *revel.Validation, file *multipart.File, header *multipart.FileHeader, formField string) bool {
if !strings.Contains(IMAGE_EXTS, strings.ToLower(path.Ext(header.Filename))) {
err := &revel.ValidationError{
Message: "只能上传图片",
Key: formField,
}
v.Errors = append(v.Errors, err)
return false
}
if (*file).(Sizer).Size() > IMAGE_LIMIT_SIZE {
err := &revel.ValidationError{
Message: fmt.Sprintf("图片尺寸不超过%dKB", IMAGE_LIMIT_SIZE),
Key: formField,
}
v.Errors = append(v.Errors, err)
return false
}
return true
}
示例5: checkFileExt
func checkFileExt(v *revel.Validation, header *multipart.FileHeader, fileExts, formField, message string) bool {
if !strings.Contains(fileExts, strings.ToLower(path.Ext(header.Filename))) {
err := &revel.ValidationError{
Message: message,
Key: formField,
}
v.Errors = append(v.Errors, err)
return false
}
return true
}
示例6: Validate
func (topic Topic) Validate(v *revel.Validation) {
v.Required(topic.Title).Message("请输入标题")
if utf8.RuneCountInString(topic.Title) > 35 {
err := &revel.ValidationError{
Message: "最多35个字",
Key: "topic.Title",
}
v.Errors = append(v.Errors, err)
}
v.Required(topic.Category).Message("请选择分类")
v.Required(topic.Content).Message("帖子内容不能为空")
}
示例7: Validate
func (product Product) Validate(v *revel.Validation) {
v.Required(product.Name).Message("不能为空")
v.Required(product.Author).Message("不能为空")
v.Required(product.Description).Message("不能为空")
if utf8.RuneCountInString(product.Name) > 20 {
err := &revel.ValidationError{
Message: "最多20个字",
Key: "product.Name",
}
v.Errors = append(v.Errors, err)
}
}
示例8: Validate
func (category *Category) Validate(v *revel.Validation) {
valid := v.Required(category.Name).Message("请输入名称")
if valid.Ok {
if category.HasName() {
err := &revel.ValidationError{
Message: "该名称已存在",
Key: "category.Name",
}
valid.Error = err
valid.Ok = false
v.Errors = append(v.Errors, err)
}
}
}
示例9: Validation
//校验
func (user *User) Validation(q *qbs.Qbs, v *revel.Validation) {
v.Required(user.UserName).Message("请输入用户名")
v.Required(user.Email).Message("请输入邮箱")
v.Required(user.Password).Message("请输入密码")
valid := v.Email(user.Email).Message("邮箱格式错误")
if valid.Ok {
if user.HasEmail(q) {
err := &revel.ValidationError{
Message: "该邮件已经注册过",
Key: "user.Email",
}
valid.Error = err
valid.Ok = false
v.Errors = append(v.Errors, err)
}
}
v.Required(user.Password == user.AffirmPassword).Message("两次密码输入不一致")
}