NESTED
NESTED = '_nested' : string
Used to flag nested rules created with addNested() and addNestedMany()
Validator object encapsulates all methods related to data validations for a model It also provides an API to dynamically change validation rules for each model field.
Implements ArrayAccess to easily modify rules in the set
errors(array $data, boolean $newRecord = true) : array
Returns an array of fields that have failed validation. On the current model. This method will actually run validation rules over data, not just return the messages.
array | $data | The data to be checked for errors |
boolean | $newRecord | whether the data to be validated is new or to be updated. |
Array of invalid fields
field(string $name, \Cake\Validation\ValidationSet|null $set = null) : \Cake\Validation\ValidationSet
Returns a ValidationSet object containing all validation rules for a field, if passed a ValidationSet as second argument, it will replace any other rule set defined before
string | $name | [optional] The fieldname to fetch. |
\Cake\Validation\ValidationSet|null | $set | The set of rules for field |
setProvider(string $name, object|string $object) : $this
Associates an object to a name so it can be used as a provider. Providers are objects or class names that can contain methods used during validation of for deciding whether a validation rule can be applied. All validation methods, when called will receive the full list of providers stored in this validator.
string | $name | The name under which the provider should be set. |
object|string | $object | Provider object or class name. |
provider(string $name, null|object|string $object = null) : $this|object|string|null
Associates an object to a name so it can be used as a provider. Providers are objects or class names that can contain methods used during validation of for deciding whether a validation rule can be applied. All validation methods, when called will receive the full list of providers stored in this validator.
If called with no arguments, it will return the provider stored under that name if it exists, otherwise it returns this instance of chaining.
string | $name | The name under which the provider should be set. |
null|object|string | $object | Provider object or class name. |
providers() : array<mixed,string>
Get the list of providers in this validator.
None found |
offsetExists(string $field) : boolean
Returns whether a rule set is defined for a field or not
string | $field | name of the field to check |
None found |
offsetGet(string $field) : \Cake\Validation\ValidationSet
Returns the rule set for a field
string | $field | name of the field to check |
None found |
offsetSet(string $field, array|\Cake\Validation\ValidationSet $rules) : void
Sets the rule set for a field
string | $field | name of the field to set |
array|\Cake\Validation\ValidationSet | $rules | set of rules to apply to field |
None found |
offsetUnset(string $field) : void
Unsets the rule set for a field
string | $field | name of the field to unset |
None found |
getIterator() : \ArrayIterator
Returns an iterator for each of the fields to be validated
None found |
None found |
add(string $field, array|string $name, array|\Cake\Validation\ValidationRule $rule = array()) : $this
Adds a new rule to a field's rule set. If second argument is an array then rules list for the field will be replaced with second argument and third argument will be ignored.
$validator
->add('title', 'required', ['rule' => 'notBlank'])
->add('user_id', 'valid', ['rule' => 'numeric', 'message' => 'Invalid User'])
$validator->add('password', [
'size' => ['rule' => ['lengthBetween', 8, 20]],
'hasSpecialCharacter' => ['rule' => 'validateSpecialchar', 'message' => 'not valid']
]);
string | $field | The name of the field from which the rule will be added |
array|string | $name | The alias for a single rule or multiple rules array |
array|\Cake\Validation\ValidationRule | $rule | the rule to add |
None found |
addNested(string $field, \Cake\Validation\Validator $validator, string|null $message = null, string|callable|null $when = null) : $this
Adds a nested validator.
Nesting validators allows you to define validators for array types. For example, nested validators are ideal when you want to validate a sub-document, or complex array type.
This method assumes that the sub-document has a 1:1 relationship with the parent.
The providers of the parent validator will be synced into the nested validator, when errors are checked. This ensures that any validation rule providers connected in the parent will have the same values in the nested validator when rules are evaluated.
string | $field | The root field for the nested validator. |
\Cake\Validation\Validator | $validator | The nested validator. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
addNestedMany(string $field, \Cake\Validation\Validator $validator, string|null $message = null, string|callable|null $when = null) : $this
Adds a nested validator.
Nesting validators allows you to define validators for array types. For example, nested validators are ideal when you want to validate many similar sub-documents or complex array types.
This method assumes that the sub-document has a 1:N relationship with the parent.
The providers of the parent validator will be synced into the nested validator, when errors are checked. This ensures that any validation rule providers connected in the parent will have the same values in the nested validator when rules are evaluated.
string | $field | The root field for the nested validator. |
\Cake\Validation\Validator | $validator | The nested validator. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
remove(string $field, string|null $rule = null) : $this
Removes a rule from the set by its name
$validator
->remove('title', 'required')
->remove('user_id')
string | $field | The name of the field from which the rule will be removed |
string|null | $rule | the name of the rule to be removed |
None found |
requirePresence(string|array $field, boolean|string|callable $mode = true, string|null $message = null) : $this
Sets whether a field is required to be present in data array.
You can also pass array. Using an array will let you provide the following keys:
mode
individual mode for fieldmessage
individual error message for fieldYou can also set mode and message for all passed fields, the individual setting takes precedence over group settings.
string|array | $field | the name of the field or list of fields. |
boolean|string|callable | $mode | Valid values are true, false, 'create', 'update'. If a callable is passed then the field will be required only when the callback returns true. |
string|null | $message | The message to show if the field presence validation fails. |
None found |
allowEmpty(string|array $field, boolean|string|callable $when = true, string|null $message = null) : $this
Allows a field to be empty. You can also pass array.
Using an array will let you provide the following keys:
when
individual when condition for fieldYou can also set when and message for all passed fields, the individual setting takes precedence over group settings.
This is the opposite of notEmpty() which requires a field to not be empty. By using $mode equal to 'create' or 'update', you can allow fields to be empty when records are first created, or when they are updated.
// Email can be empty
$validator->allowEmpty('email');
// Email can be empty on create
$validator->allowEmpty('email', 'create');
// Email can be empty on update
$validator->allowEmpty('email', 'update');
// Email and subject can be empty on update
$validator->allowEmpty(['email', 'subject'], 'update');
// Email can be always empty, subject and content can be empty on update.
$validator->allowEmpty(
[
'email' => [
'when' => true
],
'content' => [
'message' => 'Content cannot be empty'
],
'subject'
],
'update'
);
It is possible to conditionally allow emptiness on a field by passing a callback as a second argument. The callback will receive the validation context array as argument:
$validator->allowEmpty('email', function ($context) {
return !$context['newRecord'] || $context['data']['role'] === 'admin';
});
This method will correctly detect empty file uploads and date/time/datetime fields.
Because this and notEmpty()
modify the same internal state, the last
method called will take precedence.
string|array | $field | the name of the field or a list of fields |
boolean|string|callable | $when | Indicates when the field is allowed to be empty Valid values are true (always), 'create', 'update'. If a callable is passed then the field will allowed to be empty only when the callback returns true. |
string|null | $message | The message to show if the field is not |
None found |
allowEmptyFor(string $field, integer|null $flags, boolean|string|callable $when = true, string|null $message = null) : $this
Indicate that a field can be empty.
Using an array will let you provide the following keys:
flags
individual flags for fieldwhen
individual when condition for fieldmessage
individual message for fieldYou can also set flags, when and message for all passed fields, the individual setting takes precedence over group settings.
// Email can be empty
$validator->allowEmptyFor('email', Validator::EMPTY_STRING);
// Email can be empty on create
$validator->allowEmptyFor('email', Validator::EMPTY_STRING, 'create');
// Email can be empty on update
$validator->allowEmptyFor('email', Validator::EMPTY_STRING, 'update');
It is possible to conditionally allow emptiness on a field by passing a callback as a second argument. The callback will receive the validation context array as argument:
$validator->allowEmpty('email', Validator::EMPTY_STRING, function ($context) {
return !$context['newRecord'] || $context['data']['role'] === 'admin';
});
If you want to allow other kind of empty data on a field, you need to pass other flags:
$validator->allowEmptyFor('photo', Validator::EMPTY_FILE);
$validator->allowEmptyFor('published', Validator::EMPTY_STRING | Validator::EMPTY_DATE | Validator::EMPTY_TIME);
$validator->allowEmptyFor('items', Validator::EMPTY_STRING | Validator::EMPTY_ARRAY);
You can also use convenience wrappers of this method. The following calls are the same as above:
$validator->allowEmptyFile('photo');
$validator->allowEmptyDateTime('published');
$validator->allowEmptyArray('items');
string | $field | The name of the field. |
integer|null | $flags | A bitmask of EMPTY_* flags which specify what is empty |
boolean|string|callable | $when | Indicates when the field is allowed to be empty Valid values are true (always), 'create', 'update'. If a callable is passed then the field will allowed to be empty only when the callback returns true. |
string|null | $message | The message to show if the field is not |
since | 3.7.0 |
---|
allowEmptyString(string $field, boolean|string|callable $when = true, string|null $message = null) : $this
Allows a field to be an empty string.
This method is equivalent to calling allowEmptyFor() with EMPTY_STRING flag.
string | $field | The name of the field. |
boolean|string|callable | $when | Indicates when the field is allowed to be empty Valid values are true (always), 'create', 'update'. If a callable is passed then the field will allowed to be empty only when the callback returns true. |
string|null | $message | The message to show if the field is not |
since | 3.7.0 |
---|
allowEmptyArray(string $field, boolean|string|callable $when = true, string|null $message = null) : $this
Allows a field to be an empty array.
This method is equivalent to calling allowEmptyFor() with EMPTY_STRING + EMPTY_ARRAY flags.
string | $field | The name of the field. |
boolean|string|callable | $when | Indicates when the field is allowed to be empty Valid values are true (always), 'create', 'update'. If a callable is passed then the field will allowed to be empty only when the callback returns true. |
string|null | $message | The message to show if the field is not |
since | 3.7.0 |
---|
allowEmptyFile(string $field, boolean|string|callable $when = true, string|null $message = null) : $this
Allows a field to be an empty file.
This method is equivalent to calling allowEmptyFor() with EMPTY_FILE flag.
string | $field | The name of the field. |
boolean|string|callable | $when | Indicates when the field is allowed to be empty Valid values are true (always), 'create', 'update'. If a callable is passed then the field will allowed to be empty only when the callback returns true. |
string|null | $message | The message to show if the field is not |
since | 3.7.0 |
---|
allowEmptyDate(string $field, boolean|string|callable $when = true, string|null $message = null) : $this
Allows a field to be an empty date.
This method is equivalent to calling allowEmptyFor() with EMPTY_STRING + EMPTY_DATE flags.
string | $field | The name of the field. |
boolean|string|callable | $when | Indicates when the field is allowed to be empty Valid values are true (always), 'create', 'update'. If a callable is passed then the field will allowed to be empty only when the callback returns true. |
string|null | $message | The message to show if the field is not |
since | 3.7.0 |
---|
allowEmptyTime(string $field, boolean|string|callable $when = true, string|null $message = null) : $this
Allows a field to be an empty time.
This method is equivalent to calling allowEmptyFor() with EMPTY_STRING + EMPTY_TIME flags.
string | $field | The name of the field. |
boolean|string|callable | $when | Indicates when the field is allowed to be empty Valid values are true (always), 'create', 'update'. If a callable is passed then the field will allowed to be empty only when the callback returns true. |
string|null | $message | The message to show if the field is not |
since | 3.7.0 |
---|
allowEmptyDateTime(string $field, boolean|string|callable $when = true, string|null $message = null) : $this
Allows a field to be an empty date/time.
This method is equivalent to calling allowEmptyFor() with EMPTY_STRING + EMPTY_DATE + EMPTY_TIME flags.
string | $field | The name of the field. |
boolean|string|callable | $when | Indicates when the field is allowed to be empty Valid values are true (always), 'create', 'update'. If a callable is passed then the field will allowed to be empty only when the callback returns true. |
string|null | $message | The message to show if the field is not |
since | 3.7.0 |
---|
notEmpty(string|array $field, string|null $message = null, boolean|string|callable $when = false) : $this
Sets a field to require a non-empty value. You can also pass array.
Using an array will let you provide the following keys:
when
individual when condition for fieldmessage
individual error message for fieldYou can also set when
and message
for all passed fields, the individual setting
takes precedence over group settings.
This is the opposite of allowEmpty()
which allows a field to be empty.
By using $mode equal to 'create' or 'update', you can make fields required
when records are first created, or when they are updated.
$message = 'This field cannot be empty';
// Email cannot be empty
$validator->notEmpty('email');
// Email can be empty on update, but not create
$validator->notEmpty('email', $message, 'create');
// Email can be empty on create, but required on update.
$validator->notEmpty('email', $message, 'update');
// Email and title can be empty on create, but are required on update.
$validator->notEmpty(['email', 'title'], $message, 'update');
// Email can be empty on create, title must always be not empty
$validator->notEmpty(
[
'email',
'title' => [
'when' => true,
'message' => 'Title cannot be empty'
]
],
$message,
'update'
);
It is possible to conditionally disallow emptiness on a field by passing a callback as the third argument. The callback will receive the validation context array as argument:
$validator->notEmpty('email', 'Email is required', function ($context) {
return $context['newRecord'] && $context['data']['role'] !== 'admin';
});
Because this and allowEmpty()
modify the same internal state, the last
method called will take precedence.
string|array | $field | the name of the field or list of fields |
string|null | $message | The message to show if the field is not |
boolean|string|callable | $when | Indicates when the field is not allowed to be empty. Valid values are true (always), 'create', 'update'. If a callable is passed then the field will allowed to be empty only when the callback returns false. |
None found |
notBlank(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a notBlank rule to a field.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
alphaNumeric(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add an alphanumeric rule to a field.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
lengthBetween(string $field, array $range, string|null $message = null, string|callable|null $when = null) : $this
Add an rule that ensures a string length is within a range.
string | $field | The field you want to apply the rule to. |
array | $range | The inclusive minimum and maximum length you want permitted. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
creditCard(string $field, string $type = 'all', string|null $message = null, string|callable|null $when = null) : $this
Add a credit card rule to a field.
string | $field | The field you want to apply the rule to. |
string | $type | The type of cards you want to allow. Defaults to 'all'.
You can also supply an array of accepted card types. e.g |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
greaterThan(string $field, integer|float $value, string|null $message = null, string|callable|null $when = null) : $this
Add a greater than comparison rule to a field.
string | $field | The field you want to apply the rule to. |
integer|float | $value | The value user data must be greater than. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
greaterThanOrEqual(string $field, integer|float $value, string|null $message = null, string|callable|null $when = null) : $this
Add a greater than or equal to comparison rule to a field.
string | $field | The field you want to apply the rule to. |
integer|float | $value | The value user data must be greater than or equal to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
lessThan(string $field, integer|float $value, string|null $message = null, string|callable|null $when = null) : $this
Add a less than comparison rule to a field.
string | $field | The field you want to apply the rule to. |
integer|float | $value | The value user data must be less than. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
lessThanOrEqual(string $field, integer|float $value, string|null $message = null, string|callable|null $when = null) : $this
Add a less than or equal comparison rule to a field.
string | $field | The field you want to apply the rule to. |
integer|float | $value | The value user data must be less than or equal to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
equals(string $field, integer|float $value, string|null $message = null, string|callable|null $when = null) : $this
Add a equal to comparison rule to a field.
string | $field | The field you want to apply the rule to. |
integer|float | $value | The value user data must be equal to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
notEquals(string $field, integer|float $value, string|null $message = null, string|callable|null $when = null) : $this
Add a not equal to comparison rule to a field.
string | $field | The field you want to apply the rule to. |
integer|float | $value | The value user data must be not be equal to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
sameAs(string $field, string $secondField, string|null $message = null, string|callable|null $when = null) : $this
Add a rule to compare two fields to each other.
If both fields have the exact same value the rule will pass.
string | $field | The field you want to apply the rule to. |
string | $secondField | The field you want to compare against. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
notSameAs(string $field, string $secondField, string|null $message = null, string|callable|null $when = null) : $this
Add a rule to compare that two fields have different values.
string | $field | The field you want to apply the rule to. |
string | $secondField | The field you want to compare against. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
since | 3.6.0 |
---|
equalToField(string $field, string $secondField, string|null $message = null, string|callable|null $when = null) : $this
Add a rule to compare one field is equal to another.
string | $field | The field you want to apply the rule to. |
string | $secondField | The field you want to compare against. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
since | 3.6.0 |
---|
notEqualToField(string $field, string $secondField, string|null $message = null, string|callable|null $when = null) : $this
Add a rule to compare one field is not equal to another.
string | $field | The field you want to apply the rule to. |
string | $secondField | The field you want to compare against. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
since | 3.6.0 |
---|
greaterThanField(string $field, string $secondField, string|null $message = null, string|callable|null $when = null) : $this
Add a rule to compare one field is greater than another.
string | $field | The field you want to apply the rule to. |
string | $secondField | The field you want to compare against. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
since | 3.6.0 |
---|
greaterThanOrEqualToField(string $field, string $secondField, string|null $message = null, string|callable|null $when = null) : $this
Add a rule to compare one field is greater than or equal to another.
string | $field | The field you want to apply the rule to. |
string | $secondField | The field you want to compare against. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
since | 3.6.0 |
---|
lessThanField(string $field, string $secondField, string|null $message = null, string|callable|null $when = null) : $this
Add a rule to compare one field is less than another.
string | $field | The field you want to apply the rule to. |
string | $secondField | The field you want to compare against. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
since | 3.6.0 |
---|
lessThanOrEqualToField(string $field, string $secondField, string|null $message = null, string|callable|null $when = null) : $this
Add a rule to compare one field is less than or equal to another.
string | $field | The field you want to apply the rule to. |
string | $secondField | The field you want to compare against. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
since | 3.6.0 |
---|
containsNonAlphaNumeric(string $field, integer $limit = 1, string|null $message = null, string|callable|null $when = null) : $this
Add a rule to check if a field contains non alpha numeric characters.
string | $field | The field you want to apply the rule to. |
integer | $limit | The minimum number of non-alphanumeric fields required. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
date(string $field, array $formats = array('ymd'), string|null $message = null, string|callable|null $when = null) : $this
Add a date format validation rule to a field.
string | $field | The field you want to apply the rule to. |
array | $formats | A list of accepted date formats. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
dateTime(string $field, array $formats = array('ymd'), string|null $message = null, string|callable|null $when = null) : $this
Add a date time format validation rule to a field.
string | $field | The field you want to apply the rule to. |
array | $formats | A list of accepted date formats. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
time(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a time format validation rule to a field.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
localizedTime(string $field, string $type = 'datetime', string|null $message = null, string|callable|null $when = null) : $this
Add a localized time, date or datetime format validation rule to a field.
string | $field | The field you want to apply the rule to. |
string | $type | Parser type, one out of 'date', 'time', and 'datetime' |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
boolean(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a boolean validation rule to a field.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
decimal(string $field, integer|null $places = null, string|null $message = null, string|callable|null $when = null) : $this
Add a decimal validation rule to a field.
string | $field | The field you want to apply the rule to. |
integer|null | $places | The number of decimal places to require. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
email(string $field, boolean $checkMX = false, string|null $message = null, string|callable|null $when = null) : $this
Add an email validation rule to a field.
string | $field | The field you want to apply the rule to. |
boolean | $checkMX | Whether or not to check the MX records. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
ip(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add an IP validation rule to a field.
This rule will accept both IPv4 and IPv6 addresses.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
ipv4(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add an IPv4 validation rule to a field.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
ipv6(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add an IPv6 validation rule to a field.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
minLength(string $field, integer $min, string|null $message = null, string|callable|null $when = null) : $this
Add a string length validation rule to a field.
string | $field | The field you want to apply the rule to. |
integer | $min | The minimum length required. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
minLengthBytes(string $field, integer $min, string|null $message = null, string|callable|null $when = null) : $this
Add a string length validation rule to a field.
string | $field | The field you want to apply the rule to. |
integer | $min | The minimum length required. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
maxLength(string $field, integer $max, string|null $message = null, string|callable|null $when = null) : $this
Add a string length validation rule to a field.
string | $field | The field you want to apply the rule to. |
integer | $max | The maximum length allowed. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
maxLengthBytes(string $field, integer $max, string|null $message = null, string|callable|null $when = null) : $this
Add a string length validation rule to a field.
string | $field | The field you want to apply the rule to. |
integer | $max | The maximum length allowed. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
numeric(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a numeric value validation rule to a field.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
naturalNumber(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a natural number validation rule to a field.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
nonNegativeInteger(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure a field is a non negative integer.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
range(string $field, array $range, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure a field is within a numeric range
string | $field | The field you want to apply the rule to. |
array | $range | The inclusive upper and lower bounds of the valid range. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
url(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure a field is a URL.
This validator does not require a protocol.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
urlWithProtocol(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure a field is a URL.
This validator requires the URL to have a protocol.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
inList(string $field, array $list, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure the field value is within a whitelist.
string | $field | The field you want to apply the rule to. |
array | $list | The list of valid options. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
uuid(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure the field is a UUID
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
uploadedFile(string $field, array $options, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure the field is an uploaded file
For options see Cake\Validation\Validation::uploadedFile()
string | $field | The field you want to apply the rule to. |
array | $options | An array of options. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
latLong(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure the field is a lat/long tuple.
e.g. <lat>, <lng>
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
latitude(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure the field is a latitude.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
longitude(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure the field is a longitude.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
ascii(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure a field contains only ascii bytes
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
utf8(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure a field contains only BMP utf8 bytes
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
utf8Extended(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure a field contains only utf8 bytes.
This rule will accept 3 and 4 byte UTF8 sequences, which are necessary for emoji.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
integer(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure a field is an integer value.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
isArray(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure that a field contains an array.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
scalar(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure that a field contains a scalar.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
hexColor(string $field, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure a field is a 6 digits hex color value.
string | $field | The field you want to apply the rule to. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
multipleOptions(string $field, array $options = array(), string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule for a multiple select. Comparison is case sensitive by default.
string | $field | The field you want to apply the rule to. |
array | $options | The options for the validator. Includes the options defined in
\Cake\Validation\Validation::multiple() and the |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
hasAtLeast(string $field, integer $count, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure that a field is an array containing at least the specified amount of elements
string | $field | The field you want to apply the rule to. |
integer | $count | The number of elements the array should at least have |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
hasAtMost(string $field, integer $count, string|null $message = null, string|callable|null $when = null) : $this
Add a validation rule to ensure that a field is an array containing at most the specified amount of elements
string | $field | The field you want to apply the rule to. |
integer | $count | The number maximum amount of elements the field should have |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
isEmptyAllowed(string $field, boolean $newRecord) : boolean
Returns whether or not a field can be left empty for a new or already existing record.
string | $field | Field name. |
boolean | $newRecord | whether the data to be validated is new or to be updated. |
None found |
isPresenceRequired(string $field, boolean $newRecord) : boolean
Returns whether or not a field can be left out for a new or already existing record.
string | $field | Field name. |
boolean | $newRecord | Whether the data to be validated is new or to be updated. |
None found |
regex(string $field, string $regex, string|null $message = null, string|callable|null $when = null) : $this
Returns whether or not a field matches against a regular expression.
string | $field | Field name. |
string | $regex | Regular expression. |
string|null | $message | The error message when the rule fails. |
string|callable|null | $when | Either 'create' or 'update' or a callable that returns true when the validation rule should be applied. |
None found |
getRequiredMessage(string $field) : string|null
Gets the required message for a field
string | $field | Field name |
None found |
getNotEmptyMessage(string $field) : string|null
Gets the notEmpty message for a field
string | $field | Field name |
None found |
None found |
_convertValidatorToArray(integer|string $fieldName, array $defaults = array(), string|array $settings = array()) : array
Converts validator to fieldName => $settings array
integer|string | $fieldName | name of field |
array | $defaults | default settings |
string|array | $settings | settings from data |
None found |
_checkPresence(\Cake\Validation\ValidationSet $field, array $context) : boolean
Returns false if any validation for the passed rule set should be stopped due to the field missing in the data array
\Cake\Validation\ValidationSet | $field | The set of rules for a field. |
array | $context | A key value list of data containing the validation context. |
None found |
_canBeEmpty(\Cake\Validation\ValidationSet $field, array $context) : boolean
Returns whether the field can be left blank according to `allowEmpty`
\Cake\Validation\ValidationSet | $field | the set of rules for a field |
array | $context | a key value list of data containing the validation context. |
None found |
_fieldIsEmpty(mixed $data) : boolean
Returns true if the field is empty in the passed data array
mixed | $data | Value to check against. |
None found |
isEmpty(mixed $data, integer $flags) : boolean
Returns true if the field is empty in the passed data array
mixed | $data | Value to check against. |
integer | $flags | A bitmask of EMPTY_* flags which specify what is empty |
None found |
_processRules(string $field, \Cake\Validation\ValidationSet $rules, array $data, boolean $newRecord) : array
Iterates over each rule in the validation set and collects the errors resulting from executing them
string | $field | The name of the field that is being processed |
\Cake\Validation\ValidationSet | $rules | the list of rules for a field |
array | $data | the full data passed to the validator |
boolean | $newRecord | whether is it a new record or an existing one |
None found |