Usage
<?php
use BlakvGhost\PHPValidator\Validator;
use BlakvGhost\PHPValidator\ValidatorException;
try {
$data = [
'username' => 'BlakvGhost',
'email' => 'example@example.com',
'score' => 42,
];
// or
// $data = $_POST;
$validator = new Validator($data, [
'username' => 'required|string',
'email' => 'required|email',
'score' => ['required','max:200', new CustomRule()],
'password' => new CustomRule(),
]);
if ($validator->isValid()) {
echo "Validation passed!";
} else {
$errors = $validator->getErrors();
print_r($errors);
}
} catch (ValidatorException $e) {
echo "Validation error: " . $e->getMessage();
}
You can also customize the validation error messages