This package is abandoned and no longer maintained. No replacement package was suggested.

Simple validator

v2.0-beta1 2017-12-06 18:21 UTC

This package is auto-updated.

Last update: 2020-05-30 20:23:17 UTC


Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads


Via Composer

composer require albert221/validation ^2.0


use Albert221\Validation\Validator;
use Albert221\Validation\Rule;

// $data = [...];

$verdicts = Validator::build()
        ->addRule(Rule\Length::class, ['min' => 4])
        ->addRule(Rule\PdoUnique::class, ['pdo' => $pdo, 'table' => 'users', 'field' => 'username'])
        ->addRule(Rule\PdoUnique::class, ['pdo' => $pdo, 'table' => 'users', 'field' => 'email'])
            ->setOption('min', 6) // You can set options that way, too!
        ->addRule(Rule\Complexity::class, ['alpha' => true, 'num' => true, 'special' => true])
            ->setMessage('Your password is too weak!')
        ->addRule(Rule\SameAs::class, ['field' => 'password']

if ($verdicts->fails()) {
    // Validation failed

// Validation passed

# Other methods

$verdicts->passes(); // Is valid?
$verdicts->forField('username'); // Get all verdicts for specified field.
$verdicts->forField('username')->passes(); // Is specified field valid?
$verdicts->toArray(); // Get all verdicts as an array.