CakePHP 1.2: Getting started with the new validation

Getting Started with form validation

Nate replied to a question about using the new validation functions in CakePHP 1.2 dev versions, note: this is subject to change, I doubt that I will update this entry later.

Some validation rules

* ‘rule’ => ‘alphaNumeric’
* ‘rule’ => array(‘between’, $min, $max)
* ‘rule’ => array(‘blank’)
* ‘rule’ => array(‘cc’, $type, $deep)
* Where $type can be ‘fast’ (a basic check that covers all card types) or ‘all’ (check all cards) or an array of one or more of the following: ‘amex’,'bankcard’, ‘diners’, disc’, ‘electron’, ‘enroute’, ‘jcb’, ‘maestro’, ‘mc’, ‘solo’, ‘switch’, ‘visa’ or ‘voyager’.
* ‘rule’ => array(‘comparison’, $operator, $compare)
* $operator may be one of the following: ‘isgreater’, ‘isless’, ‘greaterorequal’, ‘lessorequal’, ‘equalto’, ‘notequal’, or, their symbol equivalents: ‘>’, ‘<', '>=’, ‘<=', '==', '!='.
* 'rule' => array(‘custom’, $regex)
* Where $regex is a custom regular expression.
* ‘rule’ => array(‘date’, $format)
* Where $format is one of the following: ‘dmy’, ‘mdy’, ‘ymd’, ‘dMy’, ‘Mdy’, ‘My’, ‘my’. $format can also be an array containing mulitple values.
* ‘rule’ => array(‘decimal’, $precision)
* Checks that the input is a decimal number with $precision places after the decimal point.
* ‘rule’ => array(‘email’, $deep)
* If $deep is true, the email address will be checked for a valid host name.
* ‘rule’ => array(‘minLength’, $min)
* ‘rule’ => array(‘maxLength’, $max)
* ‘rule’ => array(‘numeric’)
* ‘rule’ => array(‘postal’)
* ‘rule’ => array(‘ssn’)
* ‘rule’ => array(‘url’)

More info at [CakeBaker](http://cakebaker.42dh.com/2007/01/03/validation-with-cakephp-12/)

This entry was posted in Uncategorized by Sam. Bookmark the permalink.

3 thoughts on “CakePHP 1.2: Getting started with the new validation

  1. Thanks for explaining this. I’m still having problems though. Any chance you could public a quick MVC tutorial for form validation (i.e code required in all three objects)? Would greatly appreciate it :)

  2. Can you explain how we can add custom error messages to each rule or have multiple rules for one field ?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>