Validation Class. Used for validation of model data
Offers different validation methods.
array
array
Holds an array of errors messages set in this class. These are used for debugging purposes
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
.
Returns true if field is left blank -OR- only whitespace characters are present in its value Whitespace characters include Space, Tab, Carriage Return, Newline
Validation of credit card numbers. Returns true if $check is in the proper credit card format.
Date validation, determines if the string passed is a valid date. keys that expect full month, day and year will validate leap years.
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,
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
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( string $check , string $regex )
Runs a regular expression match.
$check
$regex
_isUploadedFile( string $path )
Helper method that can be stubbed in testing.
$path
_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
_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
between( string $check , integer $min , integer $max )
Alias of Validator::lengthBetween() for backwards compatibility.
$check
$min
$max
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( string $check )
Boolean validation, determines if value passed is a boolean integer or true/false.
$check
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' 'all' may be passed as a sting, defaults to fast which checks format of most major credit cards if an array is used only the values of the array are checked. Example: array('amex', 'bankcard', 'maestro')
$deep
optional false $regex
optional null comparison( string|array $check1 , string $operator null , integer $check2 null )
Used to compare 2 numeric values.
$check1
if string is passed for a string must also be passed for $check2 used as an array it must be passed as array('check1' => value, 'operator' => 'value', 'check2' -> value)
$operator
optional null Can be either a word or operand is greater >, is less <, greater or equal >= less or equal <=, is less <, equal to ==, not equal !=
$check2
optional null custom( string|array $check , string $regex null )
Used when a custom regular expression is needed.
$check
When used as a string, $regex must also be a valid regular expression. As and array: array('check' => value, 'regex' => 'valid regular expression')
$regex
optional null 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' Use a string or an array of the keys above. Arrays should be passed as array('dmy', 'mdy', etc)
$regex
optional null 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 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 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 equalTo( mixed $check , mixed $comparedTo )
Check that value is exactly $comparedTo.
$check
$comparedTo
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') fileSize( string|array $check , string $operator null , integer|string $size null )
Checks the filesize
$check
$operator
optional null Validation::comparison()
.$size
optional null 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 ip( string $check , string $type 'both' )
Validation of an IP address.
$check
$type
optional 'both' 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
luhn( string|array $check , boolean $deep false )
Luhn algorithm
$check
$deep
optional false maxLength( string $check , integer $max )
Checks whether the length of a string is smaller or equal to a maximal length..
$check
$max
mimeType( string|array $check , array|string $mimeTypes array() )
Checks the mime type of a file.
$check
$mimeTypes
optional array() CakeException
minLength( string $check , integer $min )
Checks whether the length of a string is greater or equal to a minimal length.
$check
$min
money( string $check , string $symbolPosition 'left' )
Checks that a value is a monetary amount.
$check
$symbolPosition
optional 'left' 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 naturalNumber( string $check , boolean $allowZero false )
Checks if a value is a natural number.
$check
$allowZero
optional false 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
notEmpty( string|array $check )
Backwards compatibility wrapper for Validation::notBlank().
$check
numeric( string $check )
Checks if a value is numeric.
$check
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' 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' 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 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 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
uploadError( string|array $check , boolean $allowNoFile false )
Checking for upload errors
$check
$allowNoFile
optional false uploadedFile( array $file , array $options array() )
Validate an uploaded file.
Helps join uploadError
, fileSize
and mimeType
into one higher level validation method.
types
- A list of valid mime types. If empty all types will be accepted. The type
will not be looked at, instead the file type will be checked with ext/finfo.minSize
- The minimum file size. Defaults to not checking.maxSize
- The maximum file size. Defaults to not checking.optional
- Whether or not this file is optional. Defaults to false. If true a missing file will pass the validator regardless of other constraints.$file
$options
optional array() 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 userDefined( string|array $check , object $object , string $method , array $args null )
Runs an user-defined validation.
$check
$object
$method
$args
optional null uuid( string $check )
Checks that a value is a valid UUID - http://tools.ietf.org/html/rfc4122
$check
protected static array
Some complex patterns needed in multiple places
array( 'hostname' => '(?:[_\p{L}0-9][-_\p{L}0-9]*\.)*(?:[\p{L}0-9][-\p{L}0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,})' )
public static array
Holds an array of errors messages set in this class. These are used for debugging purposes
array()
© 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.
https://api.cakephp.org/2.9/class-Validation.html