title |
---|
Built-in validation rules |
Required
: value should not benull
or an empty stringRequiredWith
: value is required when another item is present in the context. Rule options:item
RequiredWithout
: value is required when another item is not present in the context. Rule options:item
RequiredWhen
: value is required when another item matches another rule. Rule options:item
,rule
(class name of a validator),options
(options for the rule)
Alpha
: values must contain only letters and spacesAlphaNumeric
: values must contain letters, numbers and spacesAlphaNumHyphen
: values must contain letters, numbers, dashes, underscores and spacesLength
: value, which should be a string, must a length which is between specified limits. Rule options:min
andmax
MinLength
: string's length should be greater than a specified value. Rule options:min
MaxLength
: string's length should be shorter than a specified value. Rule options:max
FullName
: a string should represent a full name (at least 6 characters, at least 2 word, each word at least 2 characters long)
ArrayLength
: values which are arrays must contain a specific number of items. Rule options:min
andmax
ArrayMinlength
: array must contain at least a specific number of items: Rule options:min
ArrayMaxlength
: array must contain at most a specific number of items: Rule options:max
InList
: the value must be in a list of acceptable values. Rule options:list
NotInList
: the value must not be in a list of forbidden values: Rule options:list
Number
: value must be a valid numberInteger
: value must be a valid integerLessThan
: value must be less than a number. Rule options:max
andinclusive
(to determine if the comparator is < or <=, defaults to TRUE)GreaterThan
: value must be greater than a number. Rule options:min
andinclusive
(to determine if the comparator is > or >=, defaults to TRUE)Between
: value must be a number between 2 limits: Rule options:min
andmax
. The same asGreaterThan
andLessThan
, both inclusive.
Email
: value must be an email address. Uses a regular expression for validationEmailDomain
: the value, which should be an email address, must belong to a valid domain. Usescheckdnsrr
Url
: value must be a valid URL address (http, https, ftp etc)Website
: value must be a valid website address (http or https)
Date
: checks if a value in a date. Rule options:format
(a PHP date format likeY-m-d
).DateTime
: extends Date but the default format isY-m-d H:i:s
Time
: extends Date but the default format isH:i:s
Regex
: value must match a regular expression pattern. Rule options:pattern
NotRegex
: value must NOT match a regular expression pattern. Rule options:pattern
Callback
: checks if a value is valid using a custom callback (a function, an object's method, a class' static method). Rule options:callback
andarguments
(additional paramters for the callback)Match
: the value must match the value of another item in the context. Rule options:item
(eg: ifauth[password_confirm]
must matchauth[password]
theitem
isauth[password]
Equal
: the value must be the same as predefined value. Rule options:value
File validators work only with local files and they fail if the file does not exist
File\Extension
. Checks if the file has a certain extension. Rule options:allowed
which can be an array or a comma separated string.File\Image
. Checks if the file is an image of a certain type. Rule options:allowed
which can be an array or a comma separated string (default:jpg,png,gif
)File\ImageRatio
. Checks if the image has a certain ratio. Rule options:ratio
which can be a number or a string like4:3
,error_margin
- how much the file's ratio can deviate from the target (default: 0)File\ImageWidth
. Checks if the image's width is between certain limits. Rule options:min
(default: 0) andmax
(default: 1 million)File\ImageHeight
. Checks if the image's height is between certain limits. Rule options:min
(default: 0) andmax
(default: 1 million)File\Size
. Checks if the file' size is bellow a certain limit. Rule options:size
which can be a number or a string like '10K', '0.5M' or '1.3G` (default: 2M)
Upload validators work only uploaded files (each file is an upload-like array) and they fail if the temporary file does not exist.
Upload\Extension
. Checks if the uploaded file has a certain extension. Rule options:allowed
which can be an array or a comma separated string.Upload\Image
. Checks if the uploaded file is an image of a certain type. Rule options:allowed
which can be an array or a comma separated string (default:jpg,png,gif
)Upload\ImageRatio
. Checks if the uploaded image has a certain ratio. Rule options:ratio
which can be a number or a string like4:3
,error_margin
- how much the file's ratio can deviate from the target (default: 0)Upload\ImageWidth
. Checks if the uploaded image's width is between certain limits. Rule options:min
(default: 0) andmax
(default: 1 million)Upload\ImageHeight
. Checks if the uploaded image's height is between certain limits. Rule options:min
(default: 0) andmax
(default: 1 million)Upload\Size
. Checks if the uploaded file' size is bellow a certain limit. Rule options:size
which can be a number or a string like '10K', '0.5M' or '1.3G` (default: 2M)
Note! The upload validators use only the tmp_name
and name
values to perform the validation