1. Go to this page and download the library: Download infinitypaul/php-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/ */
use Infinitypaul\Validator\Rules\Rule;
class Uppercase extends Rule
{
//Determine if the validation rule passes
public function passes($field, $value, $data): bool
{
return strtoupper($value) === $value;
}
//Get the validation error message.
public function message($field): string
{
return $field.' Must Be Uppercase';
}
}
$validator = new Validator([
'name' => 'Edward Paul',
]);
$validator->setRules([
'name' => [
new Uppercase(),
'max:5'
]
]);