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) }
func ValidatePassword(v *revel.Validation, password string) *revel.ValidationResult { return v.Check(password, revel.Required{}, revel.MaxSize{15}, revel.MinSize{5}, ) }
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}, ) }
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) } } }
func (article *Article) Validate(v *revel.Validation) { v.Check(article.Title, revel.Required{}, revel.MinSize{1}, revel.MaxSize{256}, ) }
func (r *Restaurant) Validate(v *revel.Validation) { v.Check(r.Name, revel.Required{}, revel.MaxSize{150}, revel.MinSize{1}, ) }
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.") }
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") }
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") }
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}, ) }
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.") }
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}, ) }
// 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}, ) }
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}, ) }
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!!!") }
func (user *User) Validate(v *revel.Validation) { v.Check(user.Firstname, revel.Required{}, revel.MinSize{1}, revel.MaxSize{64}, ) v.Check(user.Lastname, revel.Required{}, revel.MinSize{1}, revel.MaxSize{64}, ) v.Check(user.Email, revel.Required{}, ) v.Email(user.Email) }
func (this *User) Validate(v *r.Validation, password string) { const ( EMAIL = "电子邮件地址" USERNAME = "******" PASSWORD = "******" INVALID = "不符合要求" NOEMPTY = "不能为空" ALREADYEXISTS = "已存在" ) v.Required(this.Email).Message(EMAIL + NOEMPTY) v.Check(this.Email, r.MinSize{6}, r.MaxSize{100}, r.Match{emailRegex}). Message(EMAIL + INVALID) v.Required(this.Username).Message(USERNAME + NOEMPTY) v.Check(this.Username, r.MinSize{2}, r.MaxSize{32}, r.Match{userRegex}). Message(USERNAME + INVALID) v.Required(password).Message(PASSWORD + NOEMPTY) v.Check(password, r.MaxSize{32}, r.MinSize{6}). Message(PASSWORD + INVALID) }
func UniqueEmail(v *revel.Validation, email string) *revel.ValidationResult { return v.Check(email, revel.Required{}, revel.Email{}) }
func UniqueUsername(v *revel.Validation, username string) *revel.ValidationResult { return v.Check(username, revel.Required{}) }