CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • RulesProvider
  • Validation
  • ValidationRule
  • ValidationSet
  • Validator

Interfaces

  • ValidatableInterface
  • ValidatorAwareInterface

Traits

  • ValidatorAwareTrait

Class Validation

Validation Class. Used for validation of model data

Offers different validation methods.

Namespace: Cake\Validation
Location: Validation/Validation.php

Constants summary

  • string
    COMPARE_EQUAL ¶
    '=='
  • string
    COMPARE_GREATER ¶
    '>'
  • string
    COMPARE_GREATER_OR_EQUAL ¶
    '>='
  • string
    COMPARE_LESS ¶
    '<'
  • string
    COMPARE_LESS_OR_EQUAL ¶
    '<='
  • string
    COMPARE_NOT_EQUAL ¶
    '!='
  • string
    COMPARE_NOT_SAME ¶
    '!=='
  • string
    COMPARE_SAME ¶
    '==='
  • string
    DATETIME_ISO8601 ¶
    'iso8601'
  • string
    DEFAULT_LOCALE ¶
    'en_US'

Properties summary

  • $_pattern protected static
    array
    Some complex patterns needed in multiple places
  • $errors public static
    array

    Holds an array of errors messages set in this class. These are used for debugging purposes

Method Summary

  • _check() protected static
    Runs a regular expression match.
  • _getDateString() protected static

    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.

  • _populateIp() protected static
    Lazily populate the IP address patterns used for validations
  • _reset() protected static
    Reset internal variables for another validation run.
  • alphaNumeric() public static
    Checks that a string contains only integer or letters
  • ascii() public static
    Check that the input value is within the ascii byte range.
  • blank() public static deprecated

    Returns true if field is left blank -OR- only whitespace characters are present in its value Whitespace characters include Space, Tab, Carriage Return, Newline

  • boolean() public static
    Validates if passed value is boolean-like.
  • cc() public static deprecated
    Backwards compatibility wrapper for Validation::creditCard().
  • compareFields() public static
    Compare one field to another.
  • compareWith() public static
    Compare one field to another.
  • comparison() public static
    Used to compare 2 numeric values.
  • containsNonAlphaNumeric() public static
    Checks if a string contains one or more non-alphanumeric characters.
  • creditCard() public static

    Validation of credit card numbers. Returns true if $check is in the proper credit card format.

  • custom() public static
    Used when a custom regular expression is needed.
  • date() public static

    Date validation, determines if the string passed is a valid date. keys that expect full month, day and year will validate leap years.

  • datetime() public static
    Validates a datetime value
  • decimal() public static
    Checks that a value is a valid decimal. Both the sign and exponent are optional.
  • email() public static
    Validates for an email address.
  • equalTo() public static
    Checks that value is exactly $comparedTo.
  • extension() public static
    Checks that value has a valid file extension.
  • falsey() public static
    Validates if given value is falsey.
  • fileSize() public static
    Checks the filesize
  • geoCoordinate() public static
    Validates a geographic coordinate.
  • getFilename() protected static

    Helper for reading the file out of the various file implementations we accept.

  • hexColor() public static
    Check that the input value is a 6 digits hex color.
  • iban() public static

    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

  • imageHeight() public static
    Validates the image width.
  • imageSize() public static
    Validates the size of an uploaded image.
  • imageWidth() public static
    Validates the image width.
  • inList() public static
    Checks if a value is in a given list. Comparison is case sensitive by default.
  • ip() public static
    Validation of an IP address.
  • isArray() public static
    Check that the input value is an array.
  • isInteger() public static
    Check that the input value is an integer
  • isScalar() public static
    Check that the input value is a scalar.
  • iso8601() public static

    Validates an iso8601 datetime format ISO8601 recognize datetime like 2019 as a valid date. To validate and check date integrity, use @see \Cake\Validation\Validation::datetime()

  • latitude() public static
    Convenience method for latitude validation.
  • lengthBetween() public static

    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,

  • localizedTime() public static

    Date and/or time string validation. Uses I18n::Time to parse the date. This means parsing is locale dependent.

  • longitude() public static
    Convenience method for longitude validation.
  • luhn() public static
    Luhn algorithm
  • maxLength() public static
    Checks whether the length of a string (in characters) is smaller or equal to a maximal length.
  • maxLengthBytes() public static
    Checks whether the length of a string (in bytes) is smaller or equal to a maximal length.
  • mimeType() public static
    Checks the mime type of a file.
  • minLength() public static
    Checks whether the length of a string (in characters) is greater or equal to a minimal length.
  • minLengthBytes() public static
    Checks whether the length of a string (in bytes) is greater or equal to a minimal length.
  • money() public static
    Checks that a value is a monetary amount.
  • multiple() public static
    Validates a multiple select. Comparison is case sensitive by default.
  • naturalNumber() public static
    Checks if a value is a natural number.
  • notBlank() public static
    Checks that a string contains something other than whitespace
  • notEmpty() public static deprecated
    Backwards compatibility wrapper for Validation::notBlank().
  • numElements() public static
    Used to check the count of a given value of type array or Countable.
  • numeric() public static
    Checks if a value is numeric.
  • range() public static
    Validates that a number is in specified range.
  • time() public static

    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.

  • truthy() public static
    Validates if given value is truthy.
  • uploadError() public static
    Checking for upload errors
  • uploadedFile() public static
    Validate an uploaded file.
  • url() public static
    Checks that a value is a valid URL according to https://www.w3.org/Addressing/URL/url-spec.txt
  • userDefined() public static deprecated
    Runs an user-defined validation.
  • utf8() public static
    Check that the input value is a utf8 string.
  • uuid() public static
    Checks that a value is a valid UUID - https://tools.ietf.org/html/rfc4122

Method Detail

_check() protected static ¶

_check( string $check , string $regex )

Runs a regular expression match.

Parameters
string $check
Value to check against the $regex expression
string $regex
Regular expression
Returns
boolean
Success of match

_getDateString() protected static ¶

_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.

Parameters
array $value
The array representing a date or datetime.
Returns
string

_populateIp() protected static ¶

_populateIp( )

Lazily populate the IP address patterns used for validations

_reset() protected static ¶

_reset( )

Reset internal variables for another validation run.

alphaNumeric() public static ¶

alphaNumeric( string $check )

Checks that a string contains only integer or letters

Returns true if string contains only integer or letters

Parameters
string $check
Value to check
Returns
boolean
Success

ascii() public static ¶

ascii( string $value )

Check that the input value is within the ascii byte range.

This method will reject all non-string values.

Parameters
string $value
The value to check
Returns
boolean

blank() public static deprecated ¶

blank( string $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

Deprecated
3.0.2 Validation::blank() is deprecated.
Parameters
string $check
Value to check
Returns
boolean
Success

boolean() public static ¶

boolean( boolean|integer|string $check , array $booleanValues = [] )

Validates if passed value is boolean-like.

The list of what is considered to be boolean values, may be set via $booleanValues.

Parameters
boolean|integer|string $check
Value to check.
array $booleanValues optional []
List of valid boolean values, defaults to [true, false, 0, 1, '0', '1'].
Returns
boolean
Success.

cc() public static deprecated ¶

cc( string $check , string|string[] $type = 'fast' , boolean $deep = false , string|null $regex = null )

Backwards compatibility wrapper for Validation::creditCard().

Deprecated
3.7.0 Use Validation::creditCard() instead.
Parameters
string $check
credit card number to validate
string|string[] $type optional 'fast'

'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 optional false
set to true this will check the Luhn algorithm of the credit card.
string|null $regex optional null
A custom regex can also be passed, this will be used instead of the defined regex values
Returns
boolean
Success
See
\Cake\Validation\Validation::creditCard()

compareFields() public static ¶

compareFields( mixed $check , string $field , string $operator , array $context )

Compare one field to another.

Return true if the comparison matches the expected result.

Parameters
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.
Returns
boolean
Since
3.6.0

compareWith() public static ¶

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.

Parameters
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.
Returns
boolean

comparison() public static ¶

comparison( string $check1 , string $operator , integer $check2 )

Used to compare 2 numeric values.

Parameters
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.
Returns
boolean
Success

containsNonAlphaNumeric() public static ¶

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

Parameters
string $check
Value to check
integer $count optional 1
Number of non-alphanumerics to check for
Returns
boolean
Success

creditCard() public static ¶

creditCard( string $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.

Parameters
string $check
credit card number to validate
string|array $type optional 'fast'

'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 optional false
set to true this will check the Luhn algorithm of the credit card.
string|null $regex optional null
A custom regex can also be passed, this will be used instead of the defined regex values
Returns
boolean
Success
See
\Cake\Validation\Validation::luhn()

custom() public static ¶

custom( string $check , string|null $regex = null )

Used when a custom regular expression is needed.

Parameters
string $check
The value to check.
string|null $regex optional null
If $check is passed as a string, $regex must also be set to valid regular expression
Returns
boolean
Success

date() public static ¶

date( string|DateTimeInterface $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 0001 to 2999.

Formats:

  • dmy 27-12-2006 or 27-12-06 separators can be a space, period, dash, forward slash
  • mdy 12-27-2006 or 12-27-06 separators can be a space, period, dash, forward slash
  • ymd 2006-12-27 or 06-12-27 separators can be a space, period, dash, forward slash
  • dMy 27 December 2006 or 27 Dec 2006
  • Mdy December 27, 2006 or Dec 27, 2006 comma is optional
  • My December 2006 or Dec 2006
  • my 12/2006 or 12/06 separators can be a space, period, dash, forward slash
  • ym 2006/12 or 06/12 separators can be a space, period, dash, forward slash
  • y 2006 just the year without any separators
Parameters
string|DateTimeInterface $check
a valid date string/object
string|array $format optional 'ymd'

Use a string or an array of the keys above. Arrays should be passed as ['dmy', 'mdy', etc]

string|null $regex optional null
If a custom regular expression is used this is the only validation that will occur.
Returns
boolean
Success

datetime() public static ¶

datetime( string|DateTimeInterface $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

Parameters
string|DateTimeInterface $check
Value to check
string|array $dateFormat optional 'ymd'

Format of the date part. See Validation::date() for more information. Or Validation::DATETIME_ISO8601 to valid an ISO8601 datetime value

string|null $regex optional null
Regex for the date part. If a custom regular expression is used this is the only validation that will occur.
Returns
boolean
True if the value is valid, false otherwise
See
\Cake\Validation\Validation::date()
\Cake\Validation\Validation::time()

decimal() public static ¶

decimal( float $check , integer|boolean|null $places = null , string|null $regex = null )

Checks that a value is a valid decimal. Both the sign and exponent are optional.

Valid Places:

  • null => Any number of decimal places, including none. The '.' is not required.
  • true => Any number of decimal places greater than 0, or a float|double. The '.' is required.
  • 1..N => Exactly that many number of decimal places. The '.' is required.
Parameters
float $check
The value the test for decimal.
integer|boolean|null $places optional null
Decimal places.
string|null $regex optional null
If a custom regular expression is used, this is the only validation that will occur.
Returns
boolean
Success

email() public static ¶

email( string $check , boolean $deep = false , string|null $regex = null )

Validates for an email address.

Only uses getmxrr() checking for deep validation, or any PHP version on a non-windows distribution

Parameters
string $check
Value to check
boolean $deep optional false
Perform a deeper validation (if true), by also checking availability of host
string|null $regex optional null
Regex to use (if none it will use built in regex)
Returns
boolean
Success

equalTo() public static ¶

equalTo( mixed $check , mixed $comparedTo )

Checks that value is exactly $comparedTo.

Parameters
mixed $check
Value to check
mixed $comparedTo
Value to compare
Returns
boolean
Success

extension() public static ¶

extension( string|array|Psr\Http\Message\UploadedFileInterface $check , array $extensions = ['gif', 'jpeg', 'png', 'jpg'] )

Checks that value has a valid file extension.

Parameters
string|array|Psr\Http\Message\UploadedFileInterface $check
Value to check
array $extensions optional ['gif', 'jpeg', 'png', 'jpg']
file extensions to allow. By default extensions are 'gif', 'jpeg', 'png', 'jpg'
Returns
boolean
Success

falsey() public static ¶

falsey( boolean|integer|string $check , array $falseyValues = [] )

Validates if given value is falsey.

The list of what is considered to be falsey values, may be set via $falseyValues.

Parameters
boolean|integer|string $check
Value to check.
array $falseyValues optional []
List of valid falsey values, defaults to [false, 0, '0'].
Returns
boolean
Success.

fileSize() public static ¶

fileSize( string|array|Psr\Http\Message\UploadedFileInterface $check , string|null $operator = null , integer|string|null $size = null )

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.

Parameters
string|array|Psr\Http\Message\UploadedFileInterface $check
Value to check.
string|null $operator optional null
See Validation::comparison().
integer|string|null $size optional null
Size in bytes or human readable string like '5MB'.
Returns
boolean
Success

geoCoordinate() public static ¶

geoCoordinate( string $value , array $options = [] )

Validates a geographic coordinate.

Supported formats:

  • <latitude>, <longitude> Example: -25.274398, 133.775136

Options

  • 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.
Parameters
string $value
Geographic location as string
array $options optional []
Options for the validation logic.
Returns
boolean

getFilename() protected static ¶

getFilename( string|array|Psr\Http\Message\UploadedFileInterface $check )

Helper for reading the file out of the various file implementations we accept.

Parameters
string|array|Psr\Http\Message\UploadedFileInterface $check
The data to read a filename out of.
Returns
string|boolean
Either the filename or false on failure.

hexColor() public static ¶

hexColor( string|array $check )

Check that the input value is a 6 digits hex color.

Parameters
string|array $check
The value to check
Returns
boolean
Success

iban() public static ¶

iban( string $check )

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

Parameters
string $check
The value to check
Returns
boolean
Success

imageHeight() public static ¶

imageHeight( array $file , string $operator , integer $height )

Validates the image width.

Parameters
array $file
The uploaded file data from PHP.
string $operator
Comparison operator.
integer $height
Min or max width.
Returns
boolean

imageSize() public static ¶

imageSize( array|Psr\Http\Message\UploadedFileInterface $file , array $options )

Validates the size of an uploaded image.

Parameters
array|Psr\Http\Message\UploadedFileInterface $file
The uploaded file data from PHP.
array $options
Options to validate width and height.
Returns
boolean
Throws
InvalidArgumentException

imageWidth() public static ¶

imageWidth( array $file , string $operator , integer $width )

Validates the image width.

Parameters
array $file
The uploaded file data from PHP.
string $operator
Comparison operator.
integer $width
Min or max width.
Returns
boolean

inList() public static ¶

inList( string $check , array $list , boolean $caseInsensitive = false )

Checks if a value is in a given list. Comparison is case sensitive by default.

Parameters
string $check
Value to check.
array $list
List to check against.
boolean $caseInsensitive optional false
Set to true for case insensitive comparison.
Returns
boolean
Success.

ip() public static ¶

ip( string $check , string $type = 'both' )

Validation of an IP address.

Parameters
string $check
The string to test.
string $type optional 'both'
The IP Protocol version to validate against
Returns
boolean
Success

isArray() public static ¶

isArray( array $value )

Check that the input value is an array.

Parameters
array $value
The value to check
Returns
boolean

isInteger() public static ¶

isInteger( string $value )

Check that the input value is an integer

This method will accept strings that contain only integer data as well.

Parameters
string $value
The value to check
Returns
boolean

isScalar() public static ¶

isScalar( mixed $value )

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.

Parameters
mixed $value
The value to check
Returns
boolean

iso8601() public static ¶

iso8601( string|DateTimeInterface $check )

Validates an iso8601 datetime format ISO8601 recognize datetime like 2019 as a valid date. To validate and check date integrity, use @see \Cake\Validation\Validation::datetime()

Parameters
string|DateTimeInterface $check
Value to check
Returns
boolean
True if the value is valid, false otherwise
See
Regex credits: https://www.myintervals.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/

latitude() public static ¶

latitude( string $value , array $options = [] )

Convenience method for latitude validation.

Parameters
string $value
Latitude as string
array $options optional []
Options for the validation logic.
Returns
boolean
Link
https://en.wikipedia.org/wiki/Latitude
See
\Cake\Validation\Validation::geoCoordinate()

lengthBetween() public static ¶

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,

Parameters
string $check
Value to check for length
integer $min
Minimum value in range (inclusive)
integer $max
Maximum value in range (inclusive)
Returns
boolean
Success

localizedTime() public static ¶

localizedTime( string|DateTime $check , string $type = 'datetime' , string|integer|null $format = null )

Date and/or time string validation. Uses I18n::Time to parse the date. This means parsing is locale dependent.

Parameters
string|DateTime $check
a date string or object (will always pass)
string $type optional 'datetime'
Parser type, one out of 'date', 'time', and 'datetime'
string|integer|null $format optional null
any format accepted by IntlDateFormatter
Returns
boolean
Success
Throws
InvalidArgumentException
when unsupported $type given
See
\Cake\I18n\Time::parseDate(), \Cake\I18n\Time::parseTime(), \Cake\I18n\Time::parseDateTime()

longitude() public static ¶

longitude( string $value , array $options = [] )

Convenience method for longitude validation.

Parameters
string $value
Latitude as string
array $options optional []
Options for the validation logic.
Returns
boolean
Link
https://en.wikipedia.org/wiki/Longitude
See
\Cake\Validation\Validation::geoCoordinate()

luhn() public static ¶

luhn( string|array $check )

Luhn algorithm

Parameters
string|array $check
Value to check.
Returns
boolean
Success
See
https://en.wikipedia.org/wiki/Luhn_algorithm

maxLength() public static ¶

maxLength( string $check , integer $max )

Checks whether the length of a string (in characters) is smaller or equal to a maximal length.

Parameters
string $check
The string to test
integer $max
The maximal string length
Returns
boolean
Success

maxLengthBytes() public static ¶

maxLengthBytes( string $check , integer $max )

Checks whether the length of a string (in bytes) is smaller or equal to a maximal length.

Parameters
string $check
The string to test
integer $max
The maximal string length
Returns
boolean
Success

mimeType() public static ¶

mimeType( string|array|Psr\Http\Message\UploadedFileInterface $check , array|string $mimeTypes = [] )

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.

Parameters
string|array|Psr\Http\Message\UploadedFileInterface $check
Value to check.
array|string $mimeTypes optional []
Array of mime types or regex pattern to check.
Returns
boolean
Success
Throws
RuntimeException
when mime type can not be determined.
LogicException
when ext/fileinfo is missing

minLength() public static ¶

minLength( string $check , integer $min )

Checks whether the length of a string (in characters) is greater or equal to a minimal length.

Parameters
string $check
The string to test
integer $min
The minimal string length
Returns
boolean
Success

minLengthBytes() public static ¶

minLengthBytes( string $check , integer $min )

Checks whether the length of a string (in bytes) is greater or equal to a minimal length.

Parameters
string $check
The string to test
integer $min
The minimal string length (in bytes)
Returns
boolean
Success

money() public static ¶

money( string $check , string $symbolPosition = 'left' )

Checks that a value is a monetary amount.

Parameters
string $check
Value to check
string $symbolPosition optional 'left'
Where symbol is located (left/right)
Returns
boolean
Success

multiple() public static ¶

multiple( array $check , array $options = [] , boolean $caseInsensitive = false )

Validates a multiple select. Comparison is case sensitive by default.

Valid Options

  • in => provide a list of choices that selections must be made from
  • max => maximum number of non-zero choices that can be made
  • min => minimum number of non-zero choices that can be made
Parameters
array $check
Value to check
array $options optional []
Options for the check.
boolean $caseInsensitive optional false
Set to true for case insensitive comparison.
Returns
boolean
Success

naturalNumber() public static ¶

naturalNumber( string $check , boolean $allowZero = false )

Checks if a value is a natural number.

Parameters
string $check
Value to check
boolean $allowZero optional false
Set true to allow zero, defaults to false
Returns
boolean
Success
See
https://en.wikipedia.org/wiki/Natural_number

notBlank() public static ¶

notBlank( string $check )

Checks that a string contains something other than whitespace

Returns true if string contains something other than whitespace

Parameters
string $check
Value to check
Returns
boolean
Success

notEmpty() public static deprecated ¶

notEmpty( string $check )

Backwards compatibility wrapper for Validation::notBlank().

Deprecated
3.0.2 Use Validation::notBlank() instead.
Parameters
string $check
Value to check.
Returns
boolean
Success.
See
\Cake\Validation\Validation::notBlank()

numElements() public static ¶

numElements( array|Countable $check , string $operator , integer $expectedCount )

Used to check the count of a given value of type array or Countable.

Parameters
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.
Returns
boolean
Success

numeric() public static ¶

numeric( string $check )

Checks if a value is numeric.

Parameters
string $check
Value to check
Returns
boolean
Success

range() public static ¶

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.

Parameters
string $check
Value to check
integer|float|null $lower optional null
Lower limit
integer|float|null $upper optional null
Upper limit
Returns
boolean
Success

time() public static ¶

time( string|DateTimeInterface $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.

Parameters
string|DateTimeInterface $check
a valid time string/object
Returns
boolean
Success

truthy() public static ¶

truthy( boolean|integer|string $check , array $truthyValues = [] )

Validates if given value is truthy.

The list of what is considered to be truthy values, may be set via $truthyValues.

Parameters
boolean|integer|string $check
Value to check.
array $truthyValues optional []
List of valid truthy values, defaults to [true, 1, '1'].
Returns
boolean
Success.

uploadError() public static ¶

uploadError( string|array|Psr\Http\Message\UploadedFileInterface $check , boolean $allowNoFile = false )

Checking for upload errors

Parameters
string|array|Psr\Http\Message\UploadedFileInterface $check
Value to check.
boolean $allowNoFile optional false
Set to true to allow UPLOAD_ERR_NO_FILE as a pass.
Returns
boolean
See
https://secure.php.net/manual/en/features.file-upload.errors.php

uploadedFile() public static ¶

uploadedFile( array|Psr\Http\Message\UploadedFileInterface $file , array $options = [] )

Validate an uploaded file.

Helps join uploadError, fileSize and mimeType into one higher level validation method.

Options

  • 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.
Parameters
array|Psr\Http\Message\UploadedFileInterface $file
The uploaded file data from PHP.
array $options optional []
An array of options for the validation.
Returns
boolean

url() public static ¶

url( string $check , boolean $strict = false )

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:

  • a valid, optional, scheme
  • a valid ip address OR a valid domain name as defined by section 2.3.1 of https://www.ietf.org/rfc/rfc1035.txt with an optional port number
  • an optional valid path
  • an optional query string (get parameters)
  • an optional fragment (anchor tag) as defined in RFC 3986
Parameters
string $check
Value to check
boolean $strict optional false
Require URL to be prefixed by a valid scheme (one of http(s)/ftp(s)/file/news/gopher)
Returns
boolean
Success
Link
https://tools.ietf.org/html/rfc3986

userDefined() public static deprecated ¶

userDefined( string|array $check , object $object , string $method , array|null $args = null )

Runs an user-defined validation.

Deprecated
3.0.2 You can just set a callable for rule key when adding validators.
Parameters
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 optional null
arguments to send to method
Returns
mixed
user-defined class class method returns

utf8() public static ¶

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.
Parameters
string $value
The value to check
array $options optional []
An array of options. See above for the supported options.
Returns
boolean

uuid() public static ¶

uuid( string $check )

Checks that a value is a valid UUID - https://tools.ietf.org/html/rfc4122

Parameters
string $check
Value to check
Returns
boolean
Success

Properties detail

$_pattern ¶

protected static array

Some complex patterns needed in multiple places

[
    '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,})',
    'latitude' => '[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)',
    'longitude' => '[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)',
]

$errors ¶

public static array

Holds an array of errors messages set in this class. These are used for debugging purposes

[]
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs