| title |
Built-in validation rules |
Built-in validation rules
- Required: value should not be null or an empty string
- RequiredWith: 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 spaces
- AlphaNumeric: values must contain letters, numbers and spaces
- AlphaNumHyphen: values must contain letters, numbers, dashes, underscores and spaces
- Length: value, which should be a string, must a length which is between specified limits. Rule options: min and max
- 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 and max
- 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 number
- Integer: value must be a valid integer
- LessThan: value must be less than a number. Rule options: max and inclusive (to determine if the comparator is < or <=, defaults to TRUE)
- GreaterThan: value must be greater than a number. Rule options: min and inclusive (to determine if the comparator is > or >=, defaults to TRUE)
- Between: value must be a number between 2 limits: Rule options: min and max. The same as GreaterThan and LessThan, both inclusive.
- Email: value must be an email address. Uses a regular expression for validation
- EmailDomain: the value, which should be an email address, must belong to a valid domain. Uses checkdnsrr
- 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 like Y-m-d).
- DateTime: extends Date but the default format is Y-m-d H:i:s
- Time: extends Date but the default format is H: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 and arguments (additional paramters for the callback)
- Match: the value must match the value of another item in the context. Rule options: item (eg: if auth[password_confirm] must match auth[password] the item is auth[password]
- NotMatch': the value must not match the value of another item in the context. Rule options: item(eg: ifauth[password]must not matchauth[username]theitemisauth[username]`
- Equal: the value must be the same as predefined value. Rule options: value
- NotEqual: the value must not 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 like 4: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) and max (default: 1 million)
- File\ImageHeight. Checks if the image's height is between certain limits. Rule options: min (default: 0) and max (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\Required. Checks if the uploaded file was uploaded and there are no errors.
- 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 like 4: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) and max (default: 1 million)
- Upload\ImageHeight. Checks if the uploaded image's height is between certain limits. Rule options: min (default: 0) and max (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