DEFAULT_LOCALE
DEFAULT_LOCALE = 'en_US'
Default locale
Validation Class. Used for validation of model data
Offers different validation methods.
notBlank(string $check) : boolean
Checks that a string contains something other than whitespace
Returns true if string contains something other than whitespace
string | $check | Value to check |
Success
None found |
alphaNumeric(string $check) : boolean
Checks that a string contains only integer or letters
Returns true if string contains only integer or letters
string | $check | Value to check |
Success
None found |
lengthBetween(string $check, integer $min, integer $max) : boolean
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,
string | $check | Value to check for length |
integer | $min | Minimum value in range (inclusive) |
integer | $max | Maximum value in range (inclusive) |
Success
None found |
blank(string $check) : boolean
Returns true if field is left blank -OR- only whitespace characters are present in its value Whitespace characters include Space, Tab, Carriage Return, Newline
string | $check | Value to check |
Success
None found |
cc(string $check, string|array $type = 'fast', boolean $deep = false, string|null $regex = null) : boolean
Backwards compatibility wrapper for Validation::creditCard().
string | $check | credit card number to validate |
string|array | $type | 'all' may be passed as a string, 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: ['amex', 'bankcard', 'maestro'] |
boolean | $deep | set to true this will check the Luhn algorithm of the credit card. |
string|null | $regex | A custom regex can also be passed, this will be used instead of the defined regex values |
Success
None found |
creditCard(string $check, string|array $type = 'fast', boolean $deep = false, string|null $regex = null) : boolean
Validation of credit card numbers.
Returns true if $check is in the proper credit card format.
string | $check | credit card number to validate |
string|array | $type | 'all' may be passed as a string, 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: ['amex', 'bankcard', 'maestro'] |
boolean | $deep | set to true this will check the Luhn algorithm of the credit card. |
string|null | $regex | A custom regex can also be passed, this will be used instead of the defined regex values |
Success
None found |
numElements(array|\Countable $check, string $operator, integer $expectedCount) : boolean
Used to check the count of a given value of type array or Countable.
array|\Countable | $check | The value to check the count on. |
string | $operator | Can be either a word or operand is greater >, is less <, greater or equal >= less or equal <=, is less <, equal to ==, not equal != |
integer | $expectedCount | The expected count value. |
Success
None found |
comparison(string $check1, string $operator, integer $check2) : boolean
Used to compare 2 numeric values.
string | $check1 | The left value to compare. |
string | $operator | Can be either a word or operand is greater >, is less <, greater or equal >= less or equal <=, is less <, equal to ==, not equal != |
integer | $check2 | The right value to compare. |
Success
None found |
compareWith(mixed $check, string $field, array $context) : boolean
Compare one field to another.
If both fields have exactly the same value this method will return true.
mixed | $check | The value to find in $field. |
string | $field | The field to check $check against. This field must be present in $context. |
array | $context | The validation context. |
None found |
compareFields(mixed $check, string $field, string $operator, array $context) : boolean
Compare one field to another.
Return true if the comparison matches the expected result.
mixed | $check | The value to find in $field. |
string | $field | The field to check $check against. This field must be present in $context. |
string | $operator | Comparison operator. |
array | $context | The validation context. |
since | 3.6.0 |
---|
containsNonAlphaNumeric(string $check, integer $count = 1) : boolean
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
string | $check | Value to check |
integer | $count | Number of non-alphanumerics to check for |
Success
None found |
custom(string $check, string|null $regex = null) : boolean
Used when a custom regular expression is needed.
string | $check | The value to check. |
string|null | $regex | If $check is passed as a string, $regex must also be set to valid regular expression |
Success
None found |
date(string|\DateTimeInterface $check, string|array $format = 'ymd', string|null $regex = null) : boolean
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 separatorsstring|\DateTimeInterface | $check | a valid date string/object |
string|array | $format | Use a string or an array of the keys above. Arrays should be passed as ['dmy', 'mdy', etc] |
string|null | $regex | If a custom regular expression is used this is the only validation that will occur. |
Success
None found |
datetime(string|\DateTimeInterface $check, string|array $dateFormat = 'ymd', string|null $regex = null) : boolean
Validates a datetime value
All values matching the "date" core validation rule, and the "time" one will be valid
string|\DateTimeInterface | $check | Value to check |
string|array | $dateFormat | Format of the date part. See Validation::date() for more information. |
string|null | $regex | Regex for the date part. If a custom regular expression is used this is the only validation that will occur. |
True if the value is valid, false otherwise
None found |
time(string|\DateTimeInterface $check) : boolean
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.
string|\DateTimeInterface | $check | a valid time string/object |
Success
None found |
localizedTime(string|\DateTime $check, string $type = 'datetime', string|integer|null $format = null) : boolean
Date and/or time string validation.
Uses I18n::Time
to parse the date. This means parsing is locale dependent.
string|\DateTime | $check | a date string or object (will always pass) |
string | $type | Parser type, one out of 'date', 'time', and 'datetime' |
string|integer|null | $format | any format accepted by IntlDateFormatter |
when unsupported $type given
Success
None found |
boolean(boolean|integer|string $check, array $booleanValues = array()) : boolean
Validates if passed value is boolean-like.
The list of what is considered to be boolean values, may be set via $booleanValues.
boolean|integer|string | $check | Value to check. |
array | $booleanValues | List of valid boolean values, defaults to |
Success.
None found |
truthy(boolean|integer|string $check, array $truthyValues = array()) : boolean
Validates if given value is truthy.
The list of what is considered to be truthy values, may be set via $truthyValues.
boolean|integer|string | $check | Value to check. |
array | $truthyValues | List of valid truthy values, defaults to |
Success.
None found |
falsey(boolean|integer|string $check, array $falseyValues = array()) : boolean
Validates if given value is falsey.
The list of what is considered to be falsey values, may be set via $falseyValues.
boolean|integer|string | $check | Value to check. |
array | $falseyValues | List of valid falsey values, defaults to |
Success.
None found |
decimal(float $check, integer|boolean|null $places = null, string|null $regex = null) : boolean
Checks that a value is a valid decimal. Both the sign and exponent are optional.
Valid Places:
float | $check | The value the test for decimal. |
integer|boolean|null | $places | Decimal places. |
string|null | $regex | If a custom regular expression is used, this is the only validation that will occur. |
Success
None found |
email(string $check, boolean $deep = false, string|null $regex = null) : boolean
Validates for an email address.
Only uses getmxrr() checking for deep validation, or any PHP version on a non-windows distribution
string | $check | Value to check |
boolean | $deep | Perform a deeper validation (if true), by also checking availability of host |
string|null | $regex | Regex to use (if none it will use built in regex) |
Success
None found |
equalTo(mixed $check, mixed $comparedTo) : boolean
Checks that value is exactly $comparedTo.
mixed | $check | Value to check |
mixed | $comparedTo | Value to compare |
Success
None found |
extension(string|array|\Psr\Http\Message\UploadedFileInterface $check, array $extensions = array('gif', 'jpeg', 'png', 'jpg')) : boolean
Checks that value has a valid file extension.
string|array|\Psr\Http\Message\UploadedFileInterface | $check | Value to check |
array | $extensions | file extensions to allow. By default extensions are 'gif', 'jpeg', 'png', 'jpg' |
Success
None found |
ip(string $check, string $type = 'both') : boolean
Validation of an IP address.
string | $check | The string to test. |
string | $type | The IP Protocol version to validate against |
Success
None found |
minLength(string $check, integer $min) : boolean
Checks whether the length of a string (in characters) is greater or equal to a minimal length.
string | $check | The string to test |
integer | $min | The minimal string length |
Success
None found |
maxLength(string $check, integer $max) : boolean
Checks whether the length of a string (in characters) is smaller or equal to a maximal length.
string | $check | The string to test |
integer | $max | The maximal string length |
Success
None found |
minLengthBytes(string $check, integer $min) : boolean
Checks whether the length of a string (in bytes) is greater or equal to a minimal length.
string | $check | The string to test |
integer | $min | The minimal string length (in bytes) |
Success
None found |
maxLengthBytes(string $check, integer $max) : boolean
Checks whether the length of a string (in bytes) is smaller or equal to a maximal length.
string | $check | The string to test |
integer | $max | The maximal string length |
Success
None found |
money(string $check, string $symbolPosition = 'left') : boolean
Checks that a value is a monetary amount.
string | $check | Value to check |
string | $symbolPosition | Where symbol is located (left/right) |
Success
None found |
multiple(array $check, array $options = array(), boolean $caseInsensitive = false) : boolean
Validates a multiple select. Comparison is case sensitive by default.
Valid Options
array | $check | Value to check |
array | $options | Options for the check. |
boolean | $caseInsensitive | Set to true for case insensitive comparison. |
Success
None found |
numeric(string $check) : boolean
Checks if a value is numeric.
string | $check | Value to check |
Success
None found |
naturalNumber(string $check, boolean $allowZero = false) : boolean
Checks if a value is a natural number.
string | $check | Value to check |
boolean | $allowZero | Set true to allow zero, defaults to false |
Success
None found |
range(string $check, integer|float|null $lower = null, integer|float|null $upper = null) : boolean
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.
string | $check | Value to check |
integer|float|null | $lower | Lower limit |
integer|float|null | $upper | Upper limit |
Success
None found |
url(string $check, boolean $strict = false) : boolean
Checks that a value is a valid URL according to https://www.w3.org/Addressing/URL/url-spec.txt
The regex checks for the following component parts:
string | $check | Value to check |
boolean | $strict | Require URL to be prefixed by a valid scheme (one of http(s)/ftp(s)/file/news/gopher) |
Success
None found |
inList(string $check, array $list, boolean $caseInsensitive = false) : boolean
Checks if a value is in a given list. Comparison is case sensitive by default.
string | $check | Value to check. |
array | $list | List to check against. |
boolean | $caseInsensitive | Set to true for case insensitive comparison. |
Success.
None found |
userDefined(string|array $check, object $object, string $method, array|null $args = null) : mixed
Runs an user-defined validation.
string|array | $check | value that will be validated in user-defined methods. |
object | $object | class that holds validation method |
string | $method | class method name for validation to run |
array|null | $args | arguments to send to method |
user-defined class class method returns
None found |
uuid(string $check) : boolean
Checks that a value is a valid UUID - https://tools.ietf.org/html/rfc4122
string | $check | Value to check |
Success
None found |
luhn(string|array $check) : boolean
Luhn algorithm
string|array | $check | Value to check. |
Success
None found |
mimeType(string|array|\Psr\Http\Message\UploadedFileInterface $check, array|string $mimeTypes = array()) : boolean
Checks the mime type of a file.
Will check the mimetype of files/UploadedFileInterface instances by checking the using finfo on the file, not relying on the content-type sent by the client.
string|array|\Psr\Http\Message\UploadedFileInterface | $check | Value to check. |
array|string | $mimeTypes | Array of mime types or regex pattern to check. |
when mime type can not be determined.
when ext/fileinfo is missing
Success
None found |
fileSize(string|array|\Psr\Http\Message\UploadedFileInterface $check, string|null $operator = null, integer|string|null $size = null) : boolean
Checks the filesize
Will check the filesize of files/UploadedFileInterface instances by checking the filesize() on disk and not relying on the length reported by the client.
string|array|\Psr\Http\Message\UploadedFileInterface | $check | Value to check. |
string|null | $operator | See |
integer|string|null | $size | Size in bytes or human readable string like '5MB'. |
Success
None found |
uploadError(string|array|\Psr\Http\Message\UploadedFileInterface $check, boolean $allowNoFile = false) : boolean
Checking for upload errors
string|array|\Psr\Http\Message\UploadedFileInterface | $check | Value to check. |
boolean | $allowNoFile | Set to true to allow UPLOAD_ERR_NO_FILE as a pass. |
None found |
uploadedFile(array|\Psr\Http\Message\UploadedFileInterface $file, array $options = array()) : boolean
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.array|\Psr\Http\Message\UploadedFileInterface | $file | The uploaded file data from PHP. |
array | $options | An array of options for the validation. |
None found |
imageSize(array|\Psr\Http\Message\UploadedFileInterface $file, array $options) : boolean
Validates the size of an uploaded image.
array|\Psr\Http\Message\UploadedFileInterface | $file | The uploaded file data from PHP. |
array | $options | Options to validate width and height. |
None found |
imageWidth(array $file, string $operator, integer $width) : boolean
Validates the image width.
array | $file | The uploaded file data from PHP. |
string | $operator | Comparison operator. |
integer | $width | Min or max width. |
None found |
imageHeight(array $file, string $operator, integer $height) : boolean
Validates the image width.
array | $file | The uploaded file data from PHP. |
string | $operator | Comparison operator. |
integer | $height | Min or max width. |
None found |
geoCoordinate(string $value, array $options = array()) : boolean
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.string | $value | Geographic location as string |
array | $options | Options for the validation logic. |
None found |
latitude(string $value, array $options = array()) : boolean
Convenience method for latitude validation.
string | $value | Latitude as string |
array | $options | Options for the validation logic. |
None found |
longitude(string $value, array $options = array()) : boolean
Convenience method for longitude validation.
string | $value | Latitude as string |
array | $options | Options for the validation logic. |
None found |
ascii(string $value) : boolean
Check that the input value is within the ascii byte range.
This method will reject all non-string values.
string | $value | The value to check |
None found |
utf8(string $value, array $options = array()) : boolean
Check that the input value is a utf8 string.
This method will reject all non-string values.
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.string | $value | The value to check |
array | $options | An array of options. See above for the supported options. |
None found |
isInteger(string $value) : boolean
Check that the input value is an integer
This method will accept strings that contain only integer data as well.
string | $value | The value to check |
None found |
isArray(array $value) : boolean
Check that the input value is an array.
array | $value | The value to check |
None found |
isScalar(mixed $value) : boolean
Check that the input value is a scalar.
This method will accept integers, floats, strings and booleans, but not accept arrays, objects, resources and nulls.
mixed | $value | The value to check |
None found |
hexColor(string|array $check) : boolean
Check that the input value is a 6 digits hex color.
string|array | $check | The value to check |
Success
None found |
iban(string $check) : boolean
Check that the input value has a valid International Bank Account Number IBAN syntax Requirements are uppercase, no whitespaces, max length 34, country code and checksum exist at right spots, body matches against checksum via Mod97-10 algorithm
string | $check | The value to check |
Success
None found |
_check(string $check, string $regex) : boolean
Runs a regular expression match.
string | $check | Value to check against the $regex expression |
string | $regex | Regular expression |
Success of match
None found |
getFilename(string|array|\Psr\Http\Message\UploadedFileInterface $check) : string|boolean
Helper for reading the file out of the various file implementations we accept.
string|array|\Psr\Http\Message\UploadedFileInterface | $check | The data to read a filename out of. |
Either the filename or false on failure.
None found |
_getDateString(array $value) : string
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.
array | $value | The array representing a date or datetime. |
None found |
None found |
None found |