Skip to content
Eustáquio Rangel edited this page Jun 6, 2013 · 8 revisions

Some validations are provided:

  • Presence (not empty): User::validates("name" ,array("presence"=>true))
  • Regular expression: User::validates("email",array("format" =>"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$")) There are options to allow blank and null values: "allow_blank"=>true and "allow_null"=>true
  • Uniqueness: User::validates("email",array("uniqueness"=>true))
  • Numericality: User::validates("id",array("numericality"=>true))

You can check for an valid object using $user->isValid().

For multiple validations on the same attribute, just add a validates line for each validation.