Example #1
0
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},
	)
}
Example #2
0
func (user *User) Validate(v *revel.Validation) {
	v.Check(user.UserName,
		revel.Required{},
		revel.MaxSize{36},
		revel.MinSize{4},
		revel.Match{userRegex},
	).Message("User name must be between 4 and 36 alphanumeric characters")
	v.Required(user.FirstName).
		Message("First name is required")
	v.Required(user.LastName).
		Message("Last name is required")
	v.Required(user.Password).
		Message("Password is required")
	v.Required(user.PasswordConfirm == user.Password).
		Message("The passwords do not match.")
	validatePassword(v, user.Password).Key("user.Password").
		Message("Password must be between 5 and 65 characters long")

	v.Required(user.Email).
		Message("Email is required")
	v.Email(user.Email).
		Message("Email must be valid")
	v.Required(user.TermsOfUse).
		Message("Must agree to honor code.")
}
func (s *Series) Validate(v *revel.Validation) {
	v.Check(s.Name,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{255},
	)
}
Example #4
0
func (servicedata *ServiceData) Validate() error {
	var v revel.Validation
	v.Check(
		servicedata.Name,
		revel.Required{},
		revel.MaxSize{1024},
		revel.MinSize{1},
	)
	if v.HasErrors() {
		return errors.New("name is validate error")
	}

	if servicedata.StartStr != "" {
		v.Match(servicedata.StartStr, regexp.MustCompile(`\d{8}`))
		if v.HasErrors() {
			return errors.New("start is validate error")
		}
	}

	if servicedata.EndStr != "" {
		v.Match(servicedata.EndStr, regexp.MustCompile(`\d{8}`))
		if v.HasErrors() {
			return errors.New("end is validate error")
		}
	}

	return nil
}
Example #5
0
func (a *Agent) ValidateInsert(v *revel.Validation) {
	v.Check(a.LoginPass,
		revel.MinSize{Min: 1},
		revel.MaxSize{Max: 30},
	).Key("agent.LoginPass").Message("登录密码大于1个字符小于30个字符")
	a.Validate(v)
}
func (e *Episode) Validate(v *revel.Validation) {
	v.Check(e.Name,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{255},
	)
}
Example #7
0
File: Role.go Project: qtzheng/SIMP
func (r *Role) Validate(v *revel.Validation) {
	v.Check(r.IsUse, revel.Required{})
	v.Check(r.ParentID, revel.MaxSize{50})
	v.Check(r.RoleCode, revel.Required{}, revel.MaxSize{50}, revel.MinSize{10})
	v.Check(r.RoleName, revel.Required{}, revel.MaxSize{10}, revel.MinSize{2})
	v.Check(r.Sort, revel.Required{})
}
Example #8
0
func ValidatePassword(v *revel.Validation, password string) *revel.ValidationResult {
	return v.Check(password,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{5},
	)
}
Example #9
0
func (c *Cmd) ValidateUpdate(v *revel.Validation) {
	c.Validate(v)

	c.CmdId = strings.TrimSpace(c.CmdId)
	v.Check(c.CmdId,
		revel.Required{},
	).Key("cmd.CmdId").Message("CmdId不能为空")
}
Example #10
0
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.")
}
Example #11
0
func (self *Server) Validate(v *revel.Validation) {
	//	TODO: use it in controller
	v.Check(self.Label,
		revel.Required{},
		revel.MaxSize{63},
		revel.MinSize{1},
		revel.Match{userRegex},
	)
}
Example #12
0
func (a *Account) Validate(v *revel.Validation) {
	v.Check(a.Email,
		revel.Required{},
		revel.MinSize{4},
		revel.Match{emailRegex},
	)

	ValidatePassword(v, a.Password).
		Key("account.Password")
}
Example #13
0
func (tg *TaskGroup) Validate(v *revel.Validation) {
	tg.GroupName = strings.TrimSpace(tg.GroupName)
	tg.Description = strings.TrimSpace(tg.Description)

	v.Check(tg.GroupName,
		revel.Required{},
	).Key("taskGroup.GroupName").Message("组名不能为空")
	v.Check(tg.Description,
		revel.Required{},
	).Key("taskGroup.Description").Message("描述不能为空")
}
Example #14
0
func Validate(v *revel.Validation, user models.User) {
	v.Check(user.Username,
		revel.Required{},
		revel.MaxSize{18},
		revel.MinSize{2},
		revel.Match{userRegex},
	)

	validatePassword(v, user.Password).Key("user.Password")

}
Example #15
0
//评论校验
func (comment *Comment) Validate(v *revel.Validation) {
	v.Check(comment.Email,
		revel.Required{},
		revel.MaxSize{50})
	v.Email(comment.Email)

	v.Check(comment.Content,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{1000})
}
Example #16
0
func (c *Cmd) Validate(v *revel.Validation) {
	c.Shell = strings.TrimSpace(c.Shell)
	c.AgentId = strings.TrimSpace(c.AgentId)

	v.Check(c.AgentId,
		revel.Required{},
	).Key("cmd.AgentId").Message("AgentId不能为空")

	v.Check(c.Shell,
		revel.Required{},
	).Key("cmd.Shell").Message("脚本不能为空")
}
Example #17
0
// Interface for Validate() and
// validation can pass in the key prefix ("message.")
func (message Message) Validate(v *revel.Validation) {

	v.Check(message.Name,
		revel.Required{},
		revel.MinSize{3},
	).Message("Name is required and more than 3 characters!")

	v.Required(message.Email).Message("Email is required!")

	v.Required(message.Title).Message("Title is required!")

	v.Required(message.Message).Message("Message is required!")
}
Example #18
0
func (user *User) Validate(v *revel.Validation) {
	v.Check(user.Alias,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{4},
		revel.Match{userRegex},
	)

	v.Check(user.Name,
		revel.Required{},
		revel.MaxSize{100},
	)
}
Example #19
0
func (u *Admin) Validate(v *revel.Validation) {
	v.Check(u.Username,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{4},
		revel.Match{userRegex},
	)

	v.Check(u.Password,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{5},
	)
}
Example #20
0
func (a *Agent) Validate(v *revel.Validation) {
	a.Host = strings.TrimSpace(a.Host)
	a.Port = strings.TrimSpace(a.Port)
	a.LoginName = strings.TrimSpace(a.LoginName)
	a.LoginPass = strings.TrimSpace(a.LoginPass)
	a.InitShellCmd = strings.TrimSpace(a.InitShellCmd)
	a.Memo = strings.TrimSpace(a.Memo)

	v.Check(a.Host,
		revel.Required{},
		revel.MinSize{Min: 1},
		revel.MaxSize{Max: 100},
	).Key("agent.Host").Message("主机需要大于1字符小于100个字符")
	v.Check(a.Port,
		revel.MinSize{Min: 1},
		revel.MaxSize{Max: 4},
	).Key("agent.Port").Message("端口要大于1个字符小于4个字符")
	v.Check(a.LoginName,
		revel.MinSize{Min: 1},
		revel.MaxSize{Max: 30},
	).Key("agent.LoginName").Message("登录用户名大于1个字符小于30个字符")

	v.Check(a.Memo,
		revel.MinSize{Min: 1},
		revel.MaxSize{Max: 50},
	).Key("agent.Memo").Message("备注大于1个字符小于50个字符")
}
Example #21
0
// 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},
	)
}
Example #22
0
func (u *User) Validate(v *revel.Validation) {
	u.Username = strings.TrimSpace(u.Username)
	u.Password = strings.TrimSpace(u.Password)

	v.Check(u.Username,
		revel.Required{},
		revel.MinSize{Min: 4},
		revel.MaxSize{Max: 12},
	).Key("user.Username").Message("用户名需要大于4位小于12位")
	v.Check(u.Password,
		revel.Required{},
		revel.MinSize{Min: 6},
		revel.MaxSize{Max: 12},
	).Key("user.Password").Message("密码需要大于6位小于12位")
}
Example #23
0
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.Username,
		revel.Required{},
		revel.MaxSize{100},
	)
}
Example #24
0
func (server *Server) Validate(v *revel.Validation) {
	server.Theme = strings.TrimSpace(server.Theme)
	server.Content = strings.TrimSpace(server.Content)
	server.Content = strings.Replace(server.Content, " ", "", -1)
	server.Content = strings.Replace(server.Content, "\r\n", "", -1)

	v.Check(server.Theme,
		revel.Required{},
		revel.MinSize{Min: 1},
		revel.MaxSize{Max: 100},
	).Key("server.Theme").Message("主题需要大于1字符小于100个字符")
	v.Check(server.Content,
		revel.Required{},
		revel.MinSize{Min: 1},
		revel.MaxSize{Max: 30000},
	).Key("server.Content").Message("内容要大于1个字符小于50000个字符")
}
Example #25
0
// Validate for userData of struct
func (userdata *UserData) Validate() error {
	var v revel.Validation

	v.Match(userdata.MailAddr, regexp.MustCompile(`([a-zA-Z0-9])[email protected]`))
	if v.HasErrors() {
		return errors.New("mail address is validate error")
	}

	v.Check(
		userdata.Password,
		revel.Required{},
		revel.MinSize{4},
	)
	if v.HasErrors() {
		return errors.New("password is validate error")
	}

	return nil
}
Example #26
0
func (message *Message) Validate(v *revel.Validation) {
	v.Check(message.Email,
		revel.Required{},
		revel.MaxSize{50})
	v.Email(message.Email)
	v.Check(message.QQ, revel.MaxSize{20})
	v.Check(message.Url, revel.MaxSize{200})
	v.Check(message.Content,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{1000})
}
Example #27
0
func (t *Task) Validate(v *revel.Validation) {
	t.TaskName = strings.TrimSpace(t.TaskName)
	// t.TaskType = strings.TrimSpace(t.TaskTypepe)
	t.Description = strings.TrimSpace(t.Description)
	t.CronSpec = strings.TrimSpace(t.CronSpec)
	// t.Concurrent = strings.TrimSpace(t.Concurrent)
	t.Command = strings.TrimSpace(t.Command)
	// t.Status = strings.TrimSpace(t.Status)
	// t.Notify = strings.TrimSpace(t.Notify)
	// t.NotifyEmail = strings.TrimSpace(t.NotifyEmail)
	// t.Timeout = strings.TrimSpace(t.Timeout)
	// t.ExecuteTimes = strings.TrimSpace(t.ExecuteTimes)

	v.Check(t.TaskName,
		revel.Required{},
	).Key("task.TaskName").Message("任务名称不能为空")
	v.Check(t.Command,
		revel.Required{},
	).Key("task.Command").Message("脚本不能为空")
}
Example #28
0
func (b *BidItem) Validate(v *revel.Validation) {

	v.Check(b.Name,
		revel.ValidRequired(),
		revel.ValidMaxSize(25))

	v.Check(b.Category,
		revel.ValidRequired(),
		revel.ValidMatch(
			regexp.MustCompile(
				"^(travel|leasure|sports|entertainment)$")))

	v.Check(b.EstimatedValue,
		revel.ValidRequired())

	v.Check(b.StartBid,
		revel.ValidRequired())

	v.Check(b.BidIncrement,
		revel.ValidRequired())
}
Example #29
0
//! model validation
func (obj UserAccount) Validate(v *revel.Validation) {

	v.Check(obj.Name, required(), min(6), max(16))
	v.Check(obj.Mailbox, required(), email())

	v.Check(obj.Password, required())

}
Example #30
0
func (i *Item) Validate(v *revel.Validation) {
	v.Check(i.Name,
		revel.ValidRequired(),
		revel.ValidMaxSize(25))
	v.Check(i.Stock,
		revel.ValidRequired())
	v.Check(i.Cost,
		revel.ValidRequired())
}