2017 © Pedro Peláez
 

library validation

Simple validator

image

albert221/validation

Simple validator

  • Wednesday, January 3, 2018
  • by Albert221
  • Repository
  • 3 Watchers
  • 12 Stars
  • 155 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 4 Versions
  • 115 % Grown

The README.md

Basic validator

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

Installation

Via Composer, (*2)

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.

The Versions

03/01 2018

dev-master

9999999-dev

Simple validator

  Sources   Download

MIT

The Requires

 

The Development Requires

06/12 2017

v2.0-beta1

2.0.0.0-beta1

Simple validator

  Sources   Download

MIT

The Requires

 

The Development Requires

06/12 2017

v1.1.1

1.1.1.0

Simple validator

  Sources   Download

MIT

The Requires

 

The Development Requires

16/11 2016

1.0.0

1.0.0.0

Simple validator

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires