本文整理匯總了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("兩次密碼輸入不一致")
}