Rails Validations

Details can be found here: Rails Guides on Validations

 1validates :content, :length => {
 2  :minimum   => 300,
 3  :maximum   => 400,
 4  :tokenizer => lambda { |str| str.scan(/\w+/) },
 5  :too_short => "must have at least %{count} words",
 6  :too_long  => "must have at most %{count} words"
 7}
 8
 9validates :name,
10  :presence => true,
11  :length => { :within => 1..255, :allow_blank => true }
12
13# format
14validates :legacy_code, :format => 
15  { :with => /\A[a-zA-Z]+\z/,
16    :message => "Only letters allowed" }
17
18# in
19validates :size, 
20  :inclusion => { :in => %w(small medium large),
21  :message => "%{value} is not a valid size" }
22
23# numericality
24validates :points, :numericality => true
25validates :games_played, :numericality => 
26  { :only_integer => true }    # Uses regex /\A[+-]?\d+\Z/
27
28# presence
29validates :order_id, :presence => true
30
31# uniqueness
32validates :email, :uniqueness => true
33validates :name, :uniqueness =>
34  { :scope => :year, :message => "should  happen once per year" }
35validates :name, :uniqueness => { :case_sensitive => false }
36
37# allow_blank
38validates :title, :length => { :is => 5 }, :allow_blank => true
39
40# allow_nil
41validates :size, :inclusion => 
42  {   :in => %w(small medium large),
43      :message => "%{value} is not a valid size" },
44  :allow_nil => true
45
46# on
47validates :email, :uniqueness => true, :on => :create
48
49# conditionals
50validates :card_number, :presence => true, :if => :paid_with_card?