Validation Class. Used for validation of model data
Offers different validation methods.
_check( string $check , string $regex )
Runs a regular expression match.
$check
$regex
boolean
_pass( string $method , mixed $check , string $classPrefix )
Attempts to pass unhandled Validation locales to a class starting with $classPrefix and ending with Validation. For example $classPrefix = 'nl', the class would be NlValidation
.
$method
$check
$classPrefix
mixed
_populateIp( )
Lazily populate the IP address patterns used for validations
alphaNumeric( string|array $check )
Checks that a string contains only integer or letters
Returns true if string contains only integer or letters
$check can be passed as an array: array('check' => 'valueToCheck');
$check
boolean
between( string $check , integer $min , integer $max )
Alias of Validator::lengthBetween() for backwards compatibility.
$check
$min
$max
boolean
blank( string|array $check )
Returns true if field is left blank -OR- only whitespace characters are present in its value Whitespace characters include Space, Tab, Carriage Return, Newline
$check can be passed as an array: array('check' => 'valueToCheck');
$check
boolean
boolean( string $check )
Boolean validation, determines if value passed is a boolean integer or true/false.
$check
boolean
cc( string|array $check , string|array $type 'fast' , boolean $deep false , string $regex null )
Validation of credit card numbers. Returns true if $check is in the proper credit card format.
$check
$type
optional 'fast' $deep
optional false $regex
optional null boolean
Validation::luhn()
comparison( string|array $check1 , string $operator null , integer $check2 null )
Used to compare 2 numeric values.
$check1
$operator
optional null $check2
optional null boolean
custom( string|array $check , string $regex null )
Used when a custom regular expression is needed.
$check
$regex
optional null boolean
date( string $check , string|array $format 'ymd' , string $regex null )
Date validation, determines if the string passed is a valid date. keys that expect full month, day and year will validate leap years.
Years are valid from 1800 to 2999.
dmy
27-12-2006 or 27-12-06 separators can be a space, period, dash, forward slashmdy
12-27-2006 or 12-27-06 separators can be a space, period, dash, forward slashymd
2006-12-27 or 06-12-27 separators can be a space, period, dash, forward slashdMy
27 December 2006 or 27 Dec 2006Mdy
December 27, 2006 or Dec 27, 2006 comma is optionalMy
December 2006 or Dec 2006my
12/2006 or 12/06 separators can be a space, period, dash, forward slashym
2006/12 or 06/12 separators can be a space, period, dash, forward slashy
2006 just the year without any separators$check
$format
optional 'ymd' $regex
optional null boolean
datetime( string $check , string|array $dateFormat 'ymd' , string $regex null )
Validates a datetime value
All values matching the "date" core validation rule, and the "time" one will be valid
$check
$dateFormat
optional 'ymd' $regex
optional null boolean
Validation::date()
Validation::time()
decimal( float $check , integer $places null , string $regex null )
Checks that a value is a valid decimal. Both the sign and exponent are optional.
Valid Places:
$check
$places
optional null $regex
optional null boolean
email( string $check , boolean $deep false , string $regex null )
Validates for an email address.
Only uses getmxrr() checking for deep validation if PHP 5.3.0+ is used, or any PHP version on a non-Windows distribution
$check
$deep
optional false $regex
optional null boolean
equalTo( mixed $check , mixed $comparedTo )
Check that value is exactly $comparedTo.
$check
$comparedTo
boolean
extension( string|array $check , array $extensions array('gif', 'jpeg', 'png', 'jpg') )
Check that value has a valid file extension.
$check
$extensions
optional array('gif', 'jpeg', 'png', 'jpg') boolean
fileSize( string|array $check , string $operator null , integer|string $size null )
Checks the filesize
$check
$operator
optional null Validation::comparison()
.$size
optional null boolean
inList( string $check , array $list , boolean $caseInsensitive false )
Checks if a value is in a given list. Comparison is case sensitive by default.
$check
$list
$caseInsensitive
optional false boolean
ip( string $check , string $type 'both' )
Validation of an IP address.
$check
$type
optional 'both' boolean
lengthBetween( string $check , integer $min , integer $max )
Checks that a string length is within s specified range. Spaces are included in the character count. Returns true is string matches value min, max, or between min and max,
$check
$min
$max
boolean
luhn( string|array $check , boolean $deep false )
Luhn algorithm
$check
$deep
optional false boolean
maxLength( string $check , integer $max )
Checks whether the length of a string is smaller or equal to a maximal length..
$check
$max
boolean
mimeType( string|array $check , array|string $mimeTypes array() )
Checks the mime type of a file.
$check
$mimeTypes
optional array() boolean
CakeException
minLength( string $check , integer $min )
Checks whether the length of a string is greater or equal to a minimal length.
$check
$min
boolean
money( string $check , string $symbolPosition 'left' )
Checks that a value is a monetary amount.
$check
$symbolPosition
optional 'left' boolean
multiple( array $check , array $options array() , boolean $caseInsensitive false )
Validate a multiple select. Comparison is case sensitive by default.
Valid Options
$check
$options
optional array() $caseInsensitive
optional false boolean
naturalNumber( string $check , boolean $allowZero false )
Checks if a value is a natural number.
$check
$allowZero
optional false boolean
notBlank( string|array $check )
Checks that a string contains something other than whitespace
Returns true if string contains something other than whitespace
$check can be passed as an array: array('check' => 'valueToCheck');
$check
boolean
notEmpty( string|array $check )
Backwards compatibility wrapper for Validation::notBlank().
$check
boolean
Validation::notBlank()
numeric( string $check )
Checks if a value is numeric.
$check
boolean
phone( string|array $check , string $regex null , string $country 'all' )
Check that a value is a valid phone number.
$check
$regex
optional null $country
optional 'all' boolean
postal( string|array $check , string $regex null , string $country 'us' )
Checks that a given value is a valid postal code.
$check
$regex
optional null $country
optional 'us' boolean
range( string $check , integer|float $lower null , integer|float $upper null )
Validate that a number is in specified range. if $lower and $upper are not set, will return true if $check is a legal finite on this platform
$check
$lower
optional null $upper
optional null boolean
ssn( string|array $check , string $regex null , string $country null )
Checks that a value is a valid Social Security Number.
$check
$regex
optional null $country
optional null boolean
time( string $check )
Time validation, determines if the string passed is a valid time. Validates time as 24hr (HH:MM) or am/pm ([H]H:MM[a|p]m) Does not allow/validate seconds.
$check
boolean
uploadError( string|array $check )
Checking for upload errors
$check
boolean
url( string $check , boolean $strict false )
Checks that a value is a valid URL according to http://www.w3.org/Addressing/URL/url-spec.txt
The regex checks for the following component parts:
$check
$strict
optional false boolean
userDefined( string|array $check , object $object , string $method , array $args null )
Runs an user-defined validation.
$check
$object
$method
$args
optional null mixed
uuid( string $check )
Checks that a value is a valid UUID - http://tools.ietf.org/html/rfc4122
$check
boolean
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.7/class-Validation.html