Albert221/validation


Developer experience focused validator.

License: MIT

Language: PHP

Keywords: validation, validator


Basic validator

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

Installation

Via Composer

composer require albert221/validation ^2.0

Usage

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

// $data = [...];

$verdicts = Validator::build()
    ->addField('username')
        ->addRule(Rule\Required::class)
        ->addRule(Rule\Length::class, ['min' => 4])
        ->addRule(Rule\PdoUnique::class, ['pdo' => $pdo, 'table' => 'users', 'field' => 'username'])
    ->addField('email')
        ->addRule(Rule\Required::class)
        ->addRule(Rule\Email::class)
        ->addRule(Rule\PdoUnique::class, ['pdo' => $pdo, 'table' => 'users', 'field' => 'email'])
    ->addField('password')
        ->addRule(Rule\Required::class)
        ->addRule(Rule\Length::class)
            ->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!')
    ->addField('confirm_password')
        ->addRule(Rule\SameAs::class, ['field' => 'password']
    ->validate($data);

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.

Project Statistics

Sourcerank 3
Repository Size 103 KB
Stars 12
Forks 1
Watchers 3
Open issues 1
Dependencies 4
Contributors 2
Tags 4
Created
Last updated
Last pushed

Top Contributors See all

Albert Wolszon Logarytm Całkowy

Packages Referencing this Repo

albert221/validation
Simple validator
Latest release v2.0-beta1 - Updated - 12 stars

Recent Tags See all

v2.0.0-beta1 December 06, 2017
v1.1.1 December 06, 2017
1.1.0 December 26, 2016
1.0.0 November 16, 2016

Something wrong with this page? Make a suggestion

Last synced: 2018-09-06 08:16:37 UTC

Login to resync this repository