Validation in Rails 3

  • :presence => true
  • :uniqueness => true
  • :numericality => true
  • :length => { :minimum => 0, maximum => 2000 }
  • :format => { :with => /.*/ }
  • :inclusion => { :in => [1,2,3] }
  • :exclusion => { :in => [1,2,3] }
  • :acceptance => true
  • :confirmation => true

Example

validates :login, :presence => true, :length => {:minimum => 4},
          :uniqueness => true, :format => { :with => /[A-Za-z0-9]+/ }
Advertisements