Пример #1
0
// ValidateCard validates whether the card's values are appropriate
// when creating a new card.
func ValidateCard(validator *revel.Validation, params url.Values) {
	validator.Clear()

	id, err := strconv.ParseInt(params.Get("CreatorID"), 0, 0)
	if err != nil {
		validator.Error("The ID of the creator should be a number").Key("creatorID")
	}
	creatorID := int(id)

	cardBody := params.Get("CardBody")
	t, err := strconv.ParseInt(params.Get("CardType"), 0, 0)
	if err != nil {
		validator.Error("Card Type should be a number").Key("cardType")
	}
	cardType := int(t)

	b, err := strconv.ParseInt(params.Get("CardBlanks"), 0, 0)
	if err != nil {
		validator.Error("Card Blanks should be a number").Key("cardBlanks")
	}
	cardBlanks := int(b)

	validator.Required(cardBody)
	validator.Range(int(cardType), 0, 1).Message("The card type can only be 0 for a white card, or 1 for a black card.")
	validator.Range(int(cardBlanks), 0, 3).Message("Card blanks must be in the range of 0 - 3.")
	if cardType == 0 {
		validator.Max(int(cardBlanks), 0).Message("You cannot have blank spaces in a card unless it is a black card.)")
	}
	validator.Min(creatorID, 0).Message("The creator ID must be greater than 0.")
}
Пример #2
0
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)
}
Пример #3
0
func (s SearchForm) Validate(v *revel.Validation, locale string) {

	if str := strings.Trim(s.Title, " "); str != "" {
		v.MinSize(str, 6).Message(revel.Message(locale, "search.form.validate.title.min", 6)).Key("s.Title")
	}

	if str := strings.Trim(s.Runtime, " "); str != "" {
		rt, err := strconv.Atoi(str)
		if err != nil {
			v.Error(revel.Message(locale, "search.form.validate.runtime.number")).Key("s.Runtime")
		} else {
			v.Range(rt, 50, 120).Message(revel.Message(locale, "search.form.validate.runtime.range")).Key("s.Runtime")
		}
	}

	if str := strings.Trim(s.OriginalAirDate, " "); str != "" {
		v.Match(str, regexp.MustCompile("^(January|February|March|April|May|June|July|August|September|October|November|December).*$")).Message(revel.Message(locale, "search.form.validate.originalairdate.match")).Key("s.OriginalAirDate")
	}

}