2017 © Pedro Peláez
 

library validator

PHP Validator class.

image

badelal2007/validator

PHP Validator class.

  • Saturday, March 3, 2018
  • by badelal2007
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Validator

Validator is a framework agnostic and fluent server side form validation package for PHP, (*1)

[Documentation]

Installation

Validator can be installed via composer just execute the following command in your project root, (*2)

composer require badelal2007/validator, (*3)

Or add the following in your composer.json file and run composer install, (*4)

"require": {
    "badelal2007/validator": "dev-master"
}

Usage

Using validator in your project is super simple, here is an example, (*5)

require_once __DIR__ . '/vendor/autoload.php';

$validator = new validator\Validator();
$validator->validate($_POST, [
    'username'         => 'required',
    'password'         => 'required|password:strong',
    'confirm_password' => 'required|same:password'
]);

#Return true if validation pass
var_dump($validator->passed());

#Return true if validation failed
var_dump($validator->failed());

#Return all errores if any
var_dump($validator->getErrors());

#Print first error if any for 'password' field
if($errors->get('password')) { echo '<span class="error">'.$errors->get('password')->first().'</span>'; }

#Print last error if any for 'password' field
if($errors->get('password')) { echo '<span class="error">'.$errors->get('password')->last().'</span>'; }

#Change 'message' for validation rule
$validator->validate($_POST, [
    'email'     => 'required--message=Please enter email|email--Please enter valid email ID.',
    'password'  => 'required'
]);

If you've files to validate you will need to merge $_POST|$_GET and with $_FILES just like the following, (*6)

$validator = new validator\Validator();
$validator->validate(array_merge($_POST, $_FILES), [
    'profile_picture' => 'file:image'
]);

Available Rules

  • required
  • email
  • password Accepts password strength like password:strong|medium|normal (default noraml)
  • number
  • file Accepts file type currently supported formats: image,video,doc
  • min
  • max
  • length
  • array
  • boolean
  • ip
  • same
  • alpha
  • alnum

The Versions

03/03 2018

dev-master

9999999-dev

PHP Validator class.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4

 

by Bade Lal

01/03 2018

v1.0

1.0.0.0

PHP Validator class.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4

 

by Bade Lal