예제 #1
0
파일: booking.go 프로젝트: pyanfield/revel
// 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},
	)
}
예제 #2
0
파일: user.go 프로젝트: pyanfield/revel
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)
}