kanfa/validator

Data validator

dev-master 2018-05-08 21:51 UTC

This package is not auto-updated.

Last update: 2024-10-27 06:02:41 UTC


README

Data validation based on rules

Basic use

$validator = new class extends \Validator\Core\AbstractValidator {};

$validator->defineRules([
    'username' => 'max(50):min(4)',
    'other' => 'equals(:username)'
]);

$data = ['username' => 'Kanfa', 'other' => 'Other'];

if ($validator->validate($data)) {
    // Action
} else {
    $errors = $validator->getErrors();
    // Error action
}