本文整理汇总了Golang中github.com/robfig/revel.Validation.Check方法的典型用法代码示例。如果您正苦于以下问题:Golang Validation.Check方法的具体用法?Golang Validation.Check怎么用?Golang Validation.Check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/robfig/revel.Validation
的用法示例。
在下文中一共展示了Validation.Check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: ValidatePassword
func ValidatePassword(v *revel.Validation, password string) *revel.ValidationResult {
return v.Check(password,
revel.Required{},
revel.MaxSize{15},
revel.MinSize{5},
)
}
示例3: Validate
func (hotel *Hotel) Validate(v *revel.Validation) {
v.Check(hotel.Name,
revel.Required{},
revel.MaxSize{50},
)
v.MaxSize(hotel.Address, 100)
v.Check(hotel.City,
revel.Required{},
revel.MaxSize{40},
)
v.Check(hotel.State,
revel.Required{},
revel.MaxSize{6},
revel.MinSize{2},
)
v.Check(hotel.Zip,
revel.Required{},
revel.MaxSize{6},
revel.MinSize{5},
)
v.Check(hotel.Country,
revel.Required{},
revel.MaxSize{40},
revel.MinSize{2},
)
}
示例4: Validate
func Validate(validation *revel.Validation, obj interface{}) {
// Get reflection data to parse validation tag data
var v reflect.Value = reflect.Indirect(reflect.ValueOf(obj))
// We only want to validate structs and their tagged fields
if v.Kind() != reflect.Struct {
panic(fmt.Sprintf("Object is not a struct. Actual kind is: %s", v.Kind()))
}
// Go through each field in the struct and check for the
// validation tag. Apply appropriate revel check as needed.
t := v.Type()
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
fieldId := fmt.Sprintf("%s.%s", t.Name(), field.Name)
var fieldValidators []revel.Validator
fieldValidators, ok := validationCache[fieldId]
if tag := field.Tag.Get(TagName); !ok && len(tag) > 0 {
fieldValidators = parseTag(tag)
validationCache[fieldId] = fieldValidators
} else if !ok {
fieldValidators = nil
validationCache[fieldId] = nil
}
if len(fieldValidators) > 0 {
validation.Check(v.FieldByName(field.Name).Interface(), fieldValidators...).Key(fieldId)
}
}
}
示例5: Validate
func (article *Article) Validate(v *revel.Validation) {
v.Check(article.Title,
revel.Required{},
revel.MinSize{1},
revel.MaxSize{256},
)
}
示例6: Validate
func (r *Restaurant) Validate(v *revel.Validation) {
v.Check(r.Name,
revel.Required{},
revel.MaxSize{150},
revel.MinSize{1},
)
}
示例7: 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.")
}
示例8: Validate
func (loginUser *LoginUser) Validate(v *revel.Validation, session *mgo.Session) {
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},
LegalUserValidator{session, loginUser.UserName},
).Message("UserName or password is wrong")
}
示例9: Validate
func (user *User) Validate(v *revel.Validation) {
v.Check(user.Username,
revel.Required{},
revel.MaxSize{15},
revel.MinSize{3},
revel.Match{userRegex},
).Key("username")
v.Check(user.Password,
revel.Required{},
revel.MaxSize{15},
revel.MinSize{3},
).Key("password")
}
示例10: Validate
func (user *User) Validate(v *revel.Validation) {
v.Check(user.Username,
revel.Required{},
revel.MaxSize{15},
revel.MinSize{4},
revel.Match{userRegex},
)
v.Check(user.Name,
revel.Required{},
revel.MaxSize{100},
)
}
示例11: 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.")
}
示例12: Validate
func (post *Post) Validate(v *revel.Validation) {
v.Check(
post.Title,
revel.Required{},
revel.MinSize{3},
revel.MaxSize{256},
)
v.Check(
post.Body,
revel.Required{},
revel.MinSize{10},
revel.MaxSize{2048},
)
}
示例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: Validate
func (user *User) Validate(v *revel.Validation) {
v.Check(user.Username,
revel.Required{},
revel.MaxSize{15},
revel.MinSize{4},
revel.Match{userRegex},
)
ValidatePassword(v, user.Password).
Key("user.Password")
v.Check(user.Name,
revel.Required{},
revel.MaxSize{100},
)
}
示例15: 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!!!")
}