Download the PHP package wijoc/validify-mi without Composer
On this page you can find all versions of the php package wijoc/validify-mi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wijoc/validify-mi
More information about wijoc/validify-mi
Files in wijoc/validify-mi
Package validify-mi
Short Description A stand alone validation for PHP and Wordpress.
License MIT
Informations about the package validify-mi
Validify-MI
Standalone PHP Validation that is compatible with procedural PHP and WordPress. This project provides a set of validation rules to simplify data validation in your projects, along with data sanitization specifically for WordPress projects. Heavily influenced by Laravel validation and rakit/validation, this project originated from a personal need and is still in beta development. All inputs are highly appreciated.
Table of Contents
- Features
- Installation
- Usage
- Validation Rules
- Required
- URL
- Numeric
- Max Length
- Min Length
- Greater Than
- Greater Than Equal
- Compare Number
- Less Than
- Less Than Equal
- Date
- Date More Than
- Date Less Than
- Date Between
- Exists
- Not Exists
- Match
- Not Match
- Files
- File Max Size
- Mime
- In
- Regex
- Sanitisation :
- 'email'
- 'textarea'
- 'text'
- 'kses'
- 'ksespost'
- Contributing
- License
Features
- Simple syntax
- Supports multiple validation rules
- Compatible with customs error messages
- Compatible with procedural PHP and WordPress
- Support Wordpress sanitazion
- Support nested validation
Installation
You can install the library via Composer:
Usage
Here is how you use the validation using ::make function. Validator::make has 4 arguments :
- Input that you want to validate.
- Rules of validation.
- Custom validation message.
- Sanitizion rules. (for now only available for wordpress project) All arguments should be an array.
Also you can validate nested input with :
Explanation
First, we prepare all the necessary parameters to initialize the validator.
-
Input to validate :
-
Validation rules :
-
Custom validation message :
Next, we initialize it with the Validator::make() function using the prepared arguments.
Afterwards, we can check if the input is validated or not using either the validate() or fails() function: validate() will return true if all input is validated, and false if input is not validated.
or On the other hand, fails() will return false if input is validated, and true if all input is not validated.
Example :
If the data is not validated, we can retrieve all errors using the errors('all') function. The 'all' argument is required to get all errors.
Alternatively, if you only want to get the first error, you can use the firstOfAll() method on top of the errors() function. Please note: If you use firstOfAll(), you don't need to add the 'all' argument to the errors() function.
Finally, you can get your validated input with the validated() function. validated() function will return an array of input if all data is validated, or an empty array if the data is not validated.
Additionally, if you are working on a WordPress project, you can use the sanitization feature. Check here for the sanitization feature.
Validation Rules
-
Required
Check if given data is empty.
-
email
Check if given data is a valid email address, using PHP FILTER_VALIDATE_EMAIL
-
url
Check if given data is a valid url, using php FILTER_VALIDATE_URL
-
numeric
Check if given data is numeric.
-
max
Check max element of array, or total character of string. A numeric value will treated as string. Use compare_number to validate numeric value.
-
min
Check min element of array, or total character of string. A numeric value will treated as string. Use compare_number to validate numeric value.
-
greater-than
Check value is greater than given parameter. Value must be numeric.
or
-
greater-than-equal
Check value is greater than or equal to given parameter. Value must be numeric.
or
-
less-than
Check value is less than given parameter. Value must be numeric.
or
-
less-than-equal
Check value is less than or equal to given parameter. Value must be numeric.
or
-
compare-number
Check value by compare with given parameter. Value must be numeric.
example :
-
date
Check value is a date and in same format as parameter.
example :
-
date-more-than
Check value is a date later than given parameter. Parameter can be other input.
example :
or :
-
date-less-than
Check value is a date older than given parameter. Parameter can be other input.
example :
or :
-
date-between
Check value is a date is between than given parameter. Parameter can be another request input.
example :
or :
-
exists
-
not-exists
-
match
Check value is a match/exactly same with given parameter. Parameter must be another request input.
Example :
-
not-match
Check value is not match or not exactly same with given parameter. Parameter must be another request input.
Example :
-
file
Check value is a files input.
or
or
-
file-max-size
Check input file size is not less than given parameter.
Example :
-
mime
Check input file mime is one of than given parameter. Parameter can be multiple splitted by " , " (comma)
Example :
-
in
Check input value is one of than given parameter. Parameter can be multiple splitted by " , " (comma)
-
regex
Check input value is match regex pattern.
Sanitisation
Sanitisation currently only works for WordPress projects, so it uses WordPress' default sanitizer functions. Usage :
-
email
This rule is using wordpress sanitize_email() function.
-
textarea
This rule is using wordpress sanitize_textarea_field() function.
-
text
This rule is using wordpress sanitize_text_field() function.
-
kses
This rule is using wordpress wp_kses() function.
-
ksespost
This rule is using wordpress wp_kses_post() function.