this module will help to do your own input validation from http request POST
or GET
.
The integration is the simple thing to do.
First you neeed to create a new instance of Validate
whitch will be use to do our validation.
While have the instance of validation, you can access check
method, with take two parameters, the source
and rules
;
$valid=new Validate();
$valid->check($source,$rules);
source
Thesource
is array object of information to be checked.
$source=[
"name"=>"wepesi",
"email"=>"[email protected]",
"link"=>"https://github.com/bim-g/wepesi_validation/",
"age"=>1
];
rules
Therules
containe all the rule for each element of the source to be checked.
// rules
$rules=[
"email"=>[
"required"=>true,
"email"=>true
]
];
This module allow to validation on:
required
: this to specifie that the key will be requirednumber
: this will check if the value is a numberpositive
: this will check if the number is positivemin
: this will check the minimum lenght of a stringmax
: this will check the maximum lenght of a stringemail
: this will check if the value is an emailurl
: this will check if the value is url or a linkmatches
: this is used tho check if two key hase the same value.
In the exampole bellow, you can see a comple procured on how to validate data-source
$source=[
"name"=>"wepesi",
"email"=>"[email protected]",
"link"=>"https://github.com/bim-g/wepesi_validation/",
"age"=>1
];
$rules=[
"email"=>[
"required"=>true,
"min"=>3,
"max"=>60,
"url"=>true
],
"link"=>[
"required"=>true,
"min"=>6,
"max"=>20,
"email"=>true
],
"age"=>[
"required"=>true,
"number"=>true,
"positive"=>true
]
];
$valid=new Validate();
$valid->check($source,$rules);
var_dump($valid->passed());
var_dump($valid->errors());