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


About this entry