- API like Laravel validation.
- Array validation.
- Custom validation messages.
- PHP 7.2 or higher
- Composer for installation
composer require "mkakpabla/validation"
Examples :
<?php
require 'vendor/autoload.php';
use Zen\Validation\Validator;
$validator = new Validator([], [
'title' => 'required|notEmpty',
'slug' => 'required|slug',
'content' => 'required|text'
]);
$validator->validate();
if(!$validator->isValid()) {
var_dump($validator->errors());
} else {
// Formulaire valide
// Traitements
}
<?php
require 'vendor/autoload.php';
use Zen\Validation\Validator;
$validator = new Validator($data, [
'title' => 'required',
]);
$validator->addErrorsMessages([
'title.required' => "le titre est obligatoire"
]);
$validator->validate();
required
- Field is requiredemail
- Field must be emailnotEmpty
- Field did not be emptyalpha
- Content of field must be alphabeticalphaNum
- Content of field must be alphanumericinteger
- Must be integer numbertext
- Field must be a textdatetime
- Field must be a datetimetime
- Field must be a timedate
- Field must be a dateslug
- Field must be a slugconfirm
- Field must be a same as another fieldmin:number
- The field under this rule must have a size biger or equal than the given numbermax:number
- The field under this rule must have a size lower or equal than the given numberbetween:min,max
- The field under this rule must have a size between min and max params