1. Go to this page and download the library: Download mousav1/validify 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/ */
use Mousav1\Validify\Validator;
$data = [
'name' => 'prefix_name',
];
$validator = new Validator($data);
$validator->field('name')
->
use Mousav1\Validify\Validator;
Validator::extend('even', function () {
return new class extends \Mousav1\Validify\Rules\Rule {
public function passes($field, $value, array $data): bool
{
return $value % 2 === 0;
}
public function name(): string
{
return 'even';
}
public function message($field): string
{
return "{$field} must be an even number.";
}
};
});
$data = ['number' => 3];
$validator = new Validator($data, [
'number' => ['even']
]);
if (!$validator->validate()) {
print_r($validator->getErrors());
}