// 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.") }