本文整理匯總了Golang中github.com/robfig/revel.Validation.MinSize方法的典型用法代碼示例。如果您正苦於以下問題:Golang Validation.MinSize方法的具體用法?Golang Validation.MinSize怎麽用?Golang Validation.MinSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/robfig/revel.Validation
的用法示例。
在下文中一共展示了Validation.MinSize方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: ValidatePassword
//驗證密碼
func (P *Password) ValidatePassword(v *revel.Validation) {
v.Required(P.Password).Message("請輸入密碼!")
v.Required(P.PasswordConfirm).Message("請輸入確認密碼!")
v.MinSize(P.Password, 6).Message("密碼最少六位!")
v.Required(P.Password == P.PasswordConfirm).Message("兩次密碼不相同!")
}
示例3: 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("密碼最少三位!")
}
示例4: Validate
func (c *Credentials) Validate(v *revel.Validation) {
v.Required(c.Email)
v.Email(c.Email)
v.MaxSize(c.Email, 32)
v.MinSize(c.Email, 5)
v.Required(c.Password)
v.MaxSize(c.Password, 128)
v.MinSize(c.Password, 6)
}
示例5: Validate
func (user *User) Validate(v *revel.Validation) {
v.Required(user.Username)
v.MinSize(user.Username, 6)
v.Required(user.FirstName)
v.Required(user.LastName)
v.Required(user.Age)
v.Range(user.Age, 16, 120)
v.Required(user.Password)
v.MinSize(user.Password, 6)
v.Required(user.PasswordConfirm)
v.Required(user.PasswordConfirm == user.Password).
Message("The passwords do not match.")
v.Required(user.Email)
v.Email(user.Email)
v.Required(user.EmailConfirm)
v.Required(user.EmailConfirm == user.Email).
Message("The email addresses do not match")
v.Required(user.TermsOfUse)
}
示例6: Validate
func (user *User) Validate(v *revel.Validation) {
/*
v.Check(user.Username,
revel.Required{},
revel.Range{revel.Min{4},revel.Max{15}},
revel.Match{userRegex},
)
v.Check(user.Email,
revel.Required{},
revel.MaxSize{50},
revel.MinSize{4},
//revel.Match{revel.emailPattern},
).Message("Email")
ValidatePassword(v, user.Password).
Key("user.Password")
v.Check(user.Name,
revel.Required{},
revel.MaxSize{100},
)
*/
v.Required(user.Username)
v.MinSize(user.Username, 6).Message("Username must be at least 6 characters")
v.Required(user.Name)
v.MinSize(user.Name, 2).Message("Name must be at least 2 characters")
v.Required(user.Email)
v.Email(user.Email)
v.MinSize(user.Email, 5)
/*
v.Required(user.Password)
v.MinSize(user.Password, 8).Message("Password must be at least 8 characters")
*/
}