本文整理匯總了Golang中github.com/robfig/revel.Validation.Match方法的典型用法代碼示例。如果您正苦於以下問題:Golang Validation.Match方法的具體用法?Golang Validation.Match怎麽用?Golang Validation.Match使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/robfig/revel.Validation
的用法示例。
在下文中一共展示了Validation.Match方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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("密碼最少三位!")
}
示例2: 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("密碼不一致")
}
示例3: Validate
// TODO: Make an interface for Validate() and then validation can pass in the
// key prefix ("booking.")
func (booking Booking) Validate(v *revel.Validation) {
v.Required(booking.User)
v.Required(booking.Hotel)
v.Required(booking.CheckInDate)
v.Required(booking.CheckOutDate)
v.Match(booking.CardNumber, regexp.MustCompile(`\d{16}`)).
Message("Credit card number must be numeric and 16 digits")
v.Check(booking.NameOnCard,
revel.Required{},
revel.MinSize{3},
revel.MaxSize{70},
)
}