Download the PHP package unicframework/validator without Composer
On this page you can find all versions of the php package unicframework/validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download unicframework/validator
More information about unicframework/validator
Files in unicframework/validator
Package validator
Short Description Validator is a server side data validation library for PHP. We can validate html form-data, objects, arrays and json etc.
License MIT
Homepage https://unicframework.github.io/validator
Informations about the package validator
Validator
Validator is a server side data validation library for PHP. Validate html form-data, objects, arrays and json etc. Validator make data validation simple.
Installation
- Install
composer
if you have not installed.
Set Validation Rules
We can set data validation rules using rules
method.
We can also use a shorthand method to set data validation rules, which is very simple and shorter.
Set Error Messages
We can set error messages using messages
method. if we don't set error messages then validator automatically generate error messages for you.
We can also use a shorthand method to set data validation rules, which is very simple and shorter.
Validate Data
Using validator we can validate html form-data, array, object and json data. Validator validate data according to rules. It will return true
if all the data are valid, otherwise it will return false
.
Validate single data :
Validate multiple sets of data :
Get Invalid Errors
We can get errors using errors
method. the errors
method return an array of errors.
Get Valid Data
We can get valid parsed data using getValidData
method. the getValidData
method return an array of valid data.
Get Invalid Data
We can get invalid parsed data using getInvalidData
method. the getInvalidData
method return an array of invalid data.
Set validation rules
Validator has a lots of predefined validation rules.
Rules | Value | Description |
---|---|---|
required | boolean | required fields check only data exists or not, it doesn't check data is empty or null. |
null | boolean | check data is empty or null, use true for empty or null and use false for non empty or not null values. |
not_null | boolean | check data is empty or null, use true for not null and use false for empty or null values. |
alphabet | boolean | match alphabetical data. use true for alphabetical and false for non alphabetical values. |
numeric | boolean | match numeric data. use true for numeric and false for non numeric values. |
alphanumeric | boolean | match alphanumeric data. use true for alphanumeric and false for non alphanumeric values. |
lowercase | boolean | match case of string. use true for lowercase and false for non lowercase values. |
uppercase | boolean | match case of string. use true for uppercase and false for non uppercase values. |
string | boolean | match string data type. use true for string and false for non string values. |
integer | boolean | match integer data type. use true for integer and false for non integer values. |
float | boolean | match float data type. use true for float and false for non float values. |
boolean | boolean | match boolean data type. use true for boolean and false for non boolean values. |
array | boolean | match array data type. use true for array and false for non array values. |
object | boolean | match object data type. use true for object and false for non object values. |
json | boolean | match json data type. use true for json and false for non json values. |
minlength | integer | match minimum length of string. |
maxlength | integer | match maximum length of string. |
min | integer | match minimum value of number. |
max | integer | match maximum value of number. |
boolean | check given email is valid email address or not. | |
file | boolean | check data is uploaded file or not. |
file_mime_type | array | match file mime type in given array. |
file_extension | array | match file extension in given array. |
min_file_size | bytes | match minimum file size. |
max_file_size | bytes | match maximum file size. |
in | array | match data in given array. |
not_in | array | match data in given array. |
equal | mixed | it will match data with given data. |
not_equal | mixed | it will match data with given data. |
Set Custom Rules
We can set predefined/custom rules for data validation.
Custom rules take a callback function with one argument. If custom rule return true
that means data is valid and if it will return false
that means data is invalid.