Download the PHP package jijihohococo/ichi-validation without Composer
On this page you can find all versions of the php package jijihohococo/ichi-validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jijihohococo/ichi-validation
More information about jijihohococo/ichi-validation
Files in jijihohococo/ichi-validation
Informations about the package ichi-validation
Ichi Validation
Ichi Validation is the fast and secure PHP validation library.
License
This package is Open Source According to MIT license
Table of Content
- Installation
- Testing
- Validation Methods
- required
- integer
- string
- bool
- double
- array
- file
- image
- confirm
- min
- max
- unique
- mime
- between
- dimensions
- width
- min_width
- max_width
- height
- min_height
- max_height
- Using Multiple Sub-Methods
- image_ratio
- Customization
- Customizing Error Message
- Customizing Validation Method
Installation
Testing
Using
You can validate the input data with JiJiHoHoCoCo\IchiValidation\Validator.
For example, let's make the request which have 'name' , 'age' and 'email'.
We want to validate that 'name' is not null, 'age' must be integer and 'email' must be not null and avialable email format string
If you want to validate the data with multiple methods, you can separate methods by adding between the methods or putting those methods in the array.
Validation Methods
While validating data, the system will add the error message to this data in the validator object if this data is not passed the validation according to the related method.
To validate the data is not null or not.
To validate the data is integer or not
To validate the data is string or not
To validate the data is boolean or not
To validate the data is double or not
To validate the data is array or not
To validate the data is in the email format or not
To validate the 's parameter is null or not
To validate the uploaded file is image or not
To validate the "field" is same as "confirm_field" or not
This code is validating the "password" request is same as "confirm_password" or not
If the data is string, it is aimed to validate the number of this data string length is greater than the declared minimum number or not.
If the data is number, it is aimed to validate this number is greater than the declared minimum number or not.
If the data is uploaded file, it is aimed to validate the size of this uploaded file is greater than the declared minimum MB number or not.
If the data is string, it is aimed to validate the number of this data string length is less than the declared maximum number or not.
If the data is number, it is aimed to validate this number is less than the declared maximum number or not.
If the data is uploaded file, it is aimed to validate the size of this uploaded file is less than the declared maximum MB number or not.
To validate the data is exist in database's table or not
You must set PDO object firstly before using this method
And then you can use this method.
Above code is validating request 'email' is same as any values of 'email_field' (column) of 'user_table' (table) or not.
Validating the data with this way is used to check the data duplication while inserting new data into database.
You can also make this way to validate the same process.
Above code is validating request 'email' is same as value of 'email_field' (column) where the id is not 1 of 'user_table' (table) or not.
Validating the data with this way is used to check the data duplication while updating the data into database.
It is used where the primary key of the table is 'id'.
If the primary key of the table is not 'id', you must use the below code
To validate the uploaded file's extension is one of the specific file extensions or not
To validate the request number is between the specific two numbers or not
To validate the uploaded image is specific dimensions or not
There are sub-methods in this method.
To validate the uploaded image's width is delcared width or not
To validate the uploaded image's width is greater than the declared minimum width or not
To validate the uploaded image's width is less than the delcared maximum width or not
To validate the uploaded image's height is delcared width or not
To validate the uploaded image's height is greater than the declared minimum height or not
To validate the uploaded image's height is less than the delcared maximum height or not
Using Multiple Sub-Methods
You can validate your image's dimensions with multiple sub-methods
To validate the uploaded image width and height is same as the declared ratio
Customization
Customizing Error Message
You can customize the error message for validation
Above code is customizing the error message when the 'required' validation method is not passed.
Above code is customizing the error message when the 'required' validation method for 'name' request is not passed.
Customizing Validation Method
If you want to create your own validation method, you must create the validation class.
You can create your validation class via commandline.
Firstly you need to created the file named "ichi" under your project folder and use the below code in this file
And then you can create the validation class in your commandline
The default file folder is "app/Validations". So after making command, the validation class you created will be in the this default file folder. If you want to change the default folder path, you can change it in your "ichi" file.
You must set the accepted validation rules in your created validation class. Let's make to accept only over age 21 in this created class to validate.
In calling your validation class
It is the validation data field name. For the example, it is 'age'.
It is the data value. For the example, it is the value of 'age' request.
You can pass other values in the constructor.