1. Go to this page and download the library: Download solbianca/validator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
solbianca / validator example snippets
use SolBianca\Validator;
$validator = new Validator;
$validator->validate([
'age' => ['value' => 20, 'rules' => ['ssed!';
} else {
var_dump($validator->errors()->all();
}
$validator->addRule('sex', function ($value) {
return in_array($value, ['male', 'female']);
})->addRuleMessage('sex', 'Field `{field}` must be male or female. Given value `{value}`.');
$validator->validate([
'fruit' => ['value' => 'male', 'rules' => ['sex']],
]);
class SomeRule implements SolBianca\Validator\Interfaces\RuleInterface
{
// some code
}
// You can add as a string
$validator->addRule('sex', SomeRule::class);
// or as an object
$validator->addRule('sex', new SomeRule());
$validator->addRule('int', function ($value) {
return (is_int($value)) && $value > 0);
})->addRuleMessage('sex', 'Field `{field}` must be integer ang greater than zero.');
$validator->validate([
'fruit' => ['value' => 'male', 'rules' => ['sex']],
]);
$validator->addRuleMessage('
$v->addRuleMessages([
'eld} needs to be an integer, but I found {value}.',
]);