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
_getDateString( array $value )
Converts an array representing a date or datetime into a ISO string. The arrays are typically sent for validation from a form generated by the CakePHP FormHelper.
$value
string
_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: ['check' => 'valueToCheck'];
$check
boolean
ascii( string $value )
Check that the input value is within the ascii byte range.
This method will reject all non-string values.
$value
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: ['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|null $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
Cake\Validation\Validation::luhn()
compareWith( mixed $check , string $field , array $context )
Compare one field to another.
If both fields have exactly the same value this method will return true.
$check
$field
$context
boolean
comparison( string $check1 , string $operator , integer $check2 )
Used to compare 2 numeric values.
$check1
$operator
$check2
boolean
containsNonAlphaNumeric( string $check , integer $count 1 )
Checks if a string contains one or more non-alphanumeric characters.
Returns true if string contains at least the specified number of non-alphanumeric characters
$check
$count
optional 1 boolean
custom( string|array $check , string|null $regex null )
Used when a custom regular expression is needed.
$check
$regex
optional null boolean
date( string|DateTime $check , string|array $format 'ymd' , string|null $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|DateTime $check , string|array $dateFormat 'ymd' , string|null $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
Cake\Validation\Validation::date()
Cake\Validation\Validation::time()
decimal( float $check , integer $places null , string|null $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, or any PHP version on a non-windows distribution
$check
$deep
optional false $regex
optional null boolean
equalTo( mixed $check , mixed $comparedTo )
Checks that value is exactly $comparedTo.
$check
$comparedTo
boolean
extension( string|array $check , array $extensions ['gif', 'jpeg', 'png', 'jpg'] )
Checks that value has a valid file extension.
$check
$extensions
optional ['gif', 'jpeg', 'png', 'jpg'] boolean
fileSize( string|array $check , string|null $operator null , integer|string|null $size null )
Checks the filesize
$check
$operator
optional null Validation::comparison()
.$size
optional null boolean
geoCoordinate( string $value , array $options [] )
Validates a geographic coordinate.
Supported formats:
<latitude>, <longitude>
Example: -25.274398, 133.775136
type
- A string of the coordinate format, right now only latLong
.format
- By default both
, can be long
and lat
as well to validate only a part of the coordinate.$value
$options
optional [] 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
isInteger( string $value )
Check that the input value is an integer
This method will accept strings that contain only integer data as well.
$value
boolean
latitude( string $value , array $options [] )
Convenience method for latitude validation.
$value
$options
optional [] boolean
Cake\Validation\Validation::geoCoordinate()
lengthBetween( string $check , integer $min , integer $max )
Checks that a string length is within specified range. Spaces are included in the character count. Returns true if string matches value min, max, or between min and max,
$check
$min
$max
boolean
longitude( string $value , array $options [] )
Convenience method for longitude validation.
$value
$options
optional [] boolean
Cake\Validation\Validation::geoCoordinate()
luhn( string|array $check )
Luhn algorithm
$check
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 [] )
Checks the mime type of a file.
$check
$mimeTypes
optional [] boolean
RuntimeException
LogicException
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 [] , boolean $caseInsensitive false )
Validates a multiple select. Comparison is case sensitive by default.
Valid Options
$check
$options
optional [] $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: ['check' => 'valueToCheck'];
$check
boolean
notEmpty( string|array $check )
Backwards compatibility wrapper for Validation::notBlank().
$check
boolean
Cake\Validation\Validation::notBlank()
numeric( string $check )
Checks if a value is numeric.
$check
boolean
range( string $check , integer|float|null $lower null , integer|float|null $upper null )
Validates that a number is in specified range.
If $lower and $upper are set, the range is inclusive. If they are not set, will return true if $check is a legal finite on this platform.
$check
$lower
optional null $upper
optional null boolean
time( string|DateTime $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 , boolean $allowNoFile false )
Checking for upload errors
$check
$allowNoFile
optional false boolean
uploadedFile( array $file , array $options [] )
Validate an uploaded file.
Helps join uploadError
, fileSize
and mimeType
into one higher level validation method.
types
- An array 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 in bytes. Defaults to not checking.maxSize
- The maximum file size in bytes. 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 [] 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|null $args null )
Runs an user-defined validation.
rule
key when adding validators.$check
$object
$method
$args
optional null mixed
utf8( string $value , array $options [] )
Check that the input value is a utf8 string.
This method will reject all non-string values.
# Options
extended
- Disallow bytes higher within the basic multilingual plane. MySQL's older utf8 encoding type does not allow characters above the basic multilingual plane. Defaults to false.$value
$options
optional [] boolean
uuid( string $check )
Checks that a value is a valid UUID - http://tools.ietf.org/html/rfc4122
$check
boolean
string | DEFAULT_LOCALE Default locale | 'en_US' |
© 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/3.1/class-Cake.Validation.Validation.html