本文整理匯總了Golang中github.com/robfig/revel.Validation.Required方法的典型用法代碼示例。如果您正苦於以下問題:Golang Validation.Required方法的具體用法?Golang Validation.Required怎麽用?Golang Validation.Required使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/robfig/revel.Validation
的用法示例。
在下文中一共展示了Validation.Required方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Validate
func (regUser *RegUser) Validate(v *revel.Validation, session *mgo.Session) {
//Check workflow:
//see @validation.go Check(obj interface{}, checks ...Validator)
//Validator is an interface, v.Check invoke v.Apply for each validator.
//Further, v.Apply invoke validator.IsSatisfied with passing obj.
//Checking result is an object of ValidationResult. The field Ok of ValidationResult
//would be true if checking success. Otherwise, Ok would be false, and another filed
//Error of ValidationResult would be non-nil, an ValidationError filled with error message
//should be assigned to Error.
v.Check(regUser.UserName,
revel.Required{},
revel.Match{USERNAME_REX},
DuplicatedUserValidator{session},
)
//validation provide an convenient method for checking Email.
//revel has a const for email rexgep, Email will use the rex to check email string.
v.Email(regUser.Email)
v.Check(regUser.Email,
DuplicatedEmailValidator{session},
)
v.Check(regUser.PasswordStr,
revel.Required{},
revel.Match{PWD_REX},
)
v.Check(regUser.ConfirmPwdStr,
revel.Required{},
revel.Match{PWD_REX},
)
//pwd and comfirm_pwd should be equal
v.Required(regUser.PasswordStr == regUser.ConfirmPwdStr).Message("The passwords do not match.")
}
示例2: Validate
func (this *Project) Validate(v *r.Validation) {
v.Check(this.Name, r.Required{}, r.MinSize{2}, r.MaxSize{64}, r.Match{projRegex})
if this.DisplayName == "" {
this.DisplayName = this.Name
}
v.Required(this.OwnerId)
}
示例3: ValidatePassword
func (user *User) ValidatePassword(v *revel.Validation, password Password) {
v.Check(password.Pass,
revel.MinSize{8},
)
v.Check(password.PassConfirm,
revel.MinSize{8},
)
v.Required(password.Pass == password.PassConfirm).Message("The passwords do not match.")
}
示例4: 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)
}
}
示例5: 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)
}
示例6: Validate
func (user *User) Validate(v *revel.Validation) {
v.Required(user.Password)
//v.MinSize(user.Password, 6)
v.Required(user.Email)
v.Email(user.Email)
if user.Email == "[email protected]" && user.Password == "test" {
user.Id = "6964943e-535a-4736-85ad-4baaa9656709"
} else {
v.Error("Sorry! invalid account ...")
}
}
示例7: 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("密碼不一致")
}
示例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: Validate
func (loginUser *LoginUser) Validate(v *revel.Validation) {
v.Check(loginUser.UserName,
revel.Required{},
revel.Match{USERNAME_REX},
).Message("UserName or password is wrong")
v.Check(loginUser.PasswordStr,
revel.Required{},
revel.Match{PWD_REX},
).Message("UserName or password is wrong")
//0: generate passing str
//1: get pwd bytes from database
//2: compare them
//test here
pwd := "testtest"
//rPwd := "testtest"
rPwd := "testtest"
v.Required(pwd == rPwd).Message("user name or password is wrong!!!")
}
示例10: Validate
func (menu *Menu) Validate(v *revel.Validation) {
v.Required(menu.Name).Message("請輸入菜單名稱!")
v.MaxSize(menu.Name, 105).Message("最多35個字")
v.Required(menu.Pid).Message("請選擇父菜單!")
v.Required(menu.Url).Message("請輸入菜單地址!")
v.Required(menu.Order).Message("請輸入排序!")
}
示例11: 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("密碼最少三位!")
}
示例12: 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("兩次密碼不相同!")
}
示例13: 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},
)
}
示例14: ValidateCreate
func (user *User) ValidateCreate(v *revel.Validation) {
validators.UniqueUsername(v, user.Username).Key("user.Username")
validators.UniqueEmail(v, user.Email).Key("user.Email")
v.Required(user.Password)
v.Required(user.PasswordConfirm)
v.Required(user.PasswordConfirm == user.Password).Message("Passwords must match")
}
示例15: 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("帖子內容不能為空")
}