2017 © Pedro Peláez
 

library secure-validator

Secure input validation library.

image

kenjis/secure-validator

Secure input validation library.

  • Thursday, July 16, 2015
  • by kenjis
  • Repository
  • 1 Watchers
  • 0 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Secure Validator

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Scrutinizer Code Quality Coverage Status Build Status, (*2)

Secure Validator is a library for input validation. It is based on Sirius Validation., (*3)

Requirements

  • PHP 5.4.0 or later

Features

Default Rules

Secure Validator promotes strict validation. It sets default validation rules to all fields., (*4)

  • ValidUtf8 checks if value is valid UTF-8 character encoding
  • IsString checks if value is string
  • NoControl checks if value does not have control characters (except for tab and newline)

And, (*5)

  • adds MaxLength 1 letter

That is you have to set (overwrite) max length rule to all fields. You don't forget it., (*6)

If a field does not match the default rules, you can remove the rules., (*7)

$validator->remove('field', 'ValidUtf8');

Fatal Rules

You can set a validation rule as fatal to detect abnormal input like an attack., (*8)

$validator->add('field', 'maxlength', ['max' => 60, 'fatal' => true]);

If a fatal rule fails, exception FatalValidationError will be thrown immediately., (*9)

Validated Data

You can get validated data only with $validator->getValidated()., (*10)

How to Use

See example.php and Sirius Validation Documentation., (*11)

$validator = new \Kenjis\Validation\Validator;
$validator->add('field', 'required | maxlength(max=60)');
if ($validator->validate($_POST)) {
    // validation passed
} else {
    // validation failed
}

See Built-in validation rules., (*12)

Added Method

Validator::filter()

Add filtering rule of Sirius\Filtration. See Built-in filters., (*13)

Validator will apply filters before validation., (*14)

$validator->filter('field', 'StringTrim');

Validator::getValidated()

Get validated values., (*15)

$allData = $validator->getValidated();

$field = $validator->getValidated('field');

Validator::getInputValue()

Get input value after filtering of specific field., (*16)

$field = $validator->getInputValue('field');

Tips

When you set required, if a rule fails, Sirius Validation will not apply any more rules to that field., (*17)

The Versions

16/07 2015

dev-master

9999999-dev

Secure input validation library.

  Sources   Download

MIT

The Requires

 

The Development Requires

validator validation security