| title |
|---|
Built-in validation rules |
Required: value should not benullor an empty stringRequiredWith: value is required when another item is present in the context. Rule options:itemRequiredWithout: value is required when another item is not present in the context. Rule options:itemRequiredWhen: 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:minandmaxMinLength: string's length should be greater than a specified value. Rule options:minMaxLength: string's length should be shorter than a specified value. Rule options:maxFullName: 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:minandmaxArrayMinlength: array must contain at least a specific number of items: Rule options:minArrayMaxlength: array must contain at most a specific number of items: Rule options:maxInList: the value must be in a list of acceptable values. Rule options:listNotInList: 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:maxandinclusive(to determine if the comparator is < or <=, defaults to TRUE)GreaterThan: value must be greater than a number. Rule options:minandinclusive(to determine if the comparator is > or >=, defaults to TRUE)Between: value must be a number between 2 limits: Rule options:minandmax. The same asGreaterThanandLessThan, 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. UsescheckdnsrrUrl: 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:sTime: extends Date but the default format isH:i:s
Regex: value must match a regular expression pattern. Rule options:patternNotRegex: value must NOT match a regular expression pattern. Rule options:patternCallback: checks if a value is valid using a custom callback (a function, an object's method, a class' static method). Rule options:callbackandarguments(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]theitemisauth[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:valueNotEqual: 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:allowedwhich can be an array or a comma separated string.File\Image. Checks if the file is an image of a certain type. Rule options:allowedwhich 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:ratiowhich 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:sizewhich 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:allowedwhich 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:allowedwhich 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:ratiowhich 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:sizewhich 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