Validates the value as alphanumeric only.
$filter->validate('field')->is('alnum');
Validates the value as alphabetic only.
$filter->validate('field')->is('alpha');
Validates the value as being within or equal to a minimum and maximum value.
$filter->validate('field')->is('between', $min, $max);
Validates the value as being blank.
$filter->validate('field1')->isBlank();
$filter->validate('field2')->isBlankOr('strlen', 3);
$filter->validate('field3')->isBlankOrNot('strlen', 3);
To validate the value as not being blank.
$filter->validate('field')->isNotBlank();
Validates the value as being a boolean, or a pseudo-boolean. Pseudo-true values include the strings '1', 'y', 'yes', and 'true'; pseudo-false values include the strings '0', 'n', 'no', and 'false'.
$filter->validate('field')->is('bool');
Validates the value using a callable/callback. The callable should take two arguments, $subject
and $field
, to indicate the subject and the field within that subject. It should return true
to pass, or false
to fail.
$filter->validate('field')->is('callback', function ($subject, $field) {
if ($subject->$field === 'foo') {
return true;
}
return false;
});
N.b.: Always use object notation (
$subject->$field
) and not array notation ($subject[$field]
) in the closure, as the Filter converts arrays to objects on the fly.
Validates the value as being a credit card number.
$filter->validate('field')->is('creditCard');
Validates the value as representing a date and/or time.
$filter->validate('field')->is('dateTime');
Validates the value as being a properly-formed email address per the various relevant RFCs. If the intl
extension is loaded, it will also allow for international domain names.
$filter->validate('field')->is('email');
Validates the value as loosely equal (==
) to the value of another
field in the subject.
$filter->validate('field')->is('equalToField', 'other_field_name');
Validates the value as loosely equal (`==') to a specified value.
$filter->validate('field')->is('equalToValue', $other_value);
Validates the value as representing a float.
$filter->validate('field')->is('float');
Validates that the value is loosely equal (==
) to a key in a given array.
$filter->validate('field')->is('inKeys', $array);
Validates the value as representing an integer.
$filter->validate('field')->is('int');
Validates that the value is strictly equal (===
) to a value in a given array.
$filter->validate('field')->is('inValues', $array);
Validates the value as an IPv4 or IPv6 address, allowing reserved and private addresses.
$filter->validate('field')->is('ip');
To modify restrictions on the filter, pass the appropriate FILTER_FLAG_*
constants (seen here) as a second parameter.
// only allow IPv4 addresses in the non-private range.
$filter->validate('field')->is('ip', FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE);
// only allow IPv6 addresses in non-reserved range.
$filter->validate('field')->is('ip', FILTER_FLAG_IPV6 | FILTER_FLAG_NO_RES_RANGE);
Validates the value is a correct ISBN (International Standard Book Number).
$filter->validate('field')->is('isbn');
Validates the given value against a list of locale strings (internal to the rule class).
$filter->validate('field')->is('locale');
Validates the value as all lowercase.
$filter->validate('field')->is('lowercase');
Validates the value begins with a lowercase character.
$filter->validate('field')->is('lowercaseFirst');
Validates the value as being less than or equal to a maximum.
$filter->validate('field')->is('max', $max);
Validates the value as being greater than or equal to a minimum.
$filter->validate('field')->is('min', $min);
Validates the value using preg_match()
.
$filter->validate('field')->is('regex', $expr);
Validates the value as strictly equal (===
) to the value of another field in the subject.
$filter->validate('field')->is('strictEqualToField', 'other_field_name');
Validates the value as strictly equal (===
) to a specified value.
$filter->validate('field')->is('strictEqualToValue', $other_value);
Validates the value can be represented by a string.
$filter->validate('field')->is('string');
Validates the value has a specified length.
$filter->validate('field')->is('strlen', $len);
Validates the value as being within or equal to a minimum and maximum length.
$filter->validate('field')->is('strlenBetween', $min, $max);
Validates the value length as being no longer than a maximum.
$filter->validate('field')->is('strlenMax', $max);
Validates the value length as being no shorter than a minimum.
$filter->validate('field')->is('strlenMin', $min);
Validates the value as title case
$filter->validate('field')->is('titlecase');
Validates the value is trim()
med. Optionally specify characters to trim.
$filter->validate('field')->is('trim', $chars);
Validates the value represents a PHP upload information array, and that the file is an uploaded file.
$filter->validate('field')->is('upload');
Validates the value as all uppercase.
$filter->validate('field')->is('uppercase');
Validates the value begins with an uppercase character.
$filter->validate('field')->is('uppercaseFirst');
Validates the value is a well-formed URL.
$filter->validate('field')->is('url');
Validates the value as being composed only of word characters.
$filter->validate('field')->is('word');