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

Previous: Models - Next: Collections

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, after the "format" option like User::validates("zip",array("format"=>"^[0-9]{5}-[0-9]{3}$","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.

Previous: Models - Next: Collections