Skip to content
Framework agnostic validation library for PHP
Branch: master
Clone or download
adrianmiu Merge pull request #56 from kulavvy/patch-1
fix checking empty value as strict
Latest commit 3c601f2 Apr 3, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Corrected link to validation helper doc on index doc Sep 27, 2018
src fix checking empty value as strict Feb 18, 2019
tests Add test to review issue 52 (empty string, that is not required, is n… Apr 4, 2018
.editorconfig Added .editorconfig file Mar 7, 2017
.gitattributes Moved everything related to the docs into the `docs` folder to prepar… May 3, 2015
.gitignore Fixed coding standard violations, added PHPCS to Travis Feb 24, 2017
.scrutinizer.yml Added scrutinizer code coverage report. Fixed some issues reported by… Feb 19, 2015
.travis.yml Run phpunit from the right location May 17, 2017 Updated docs and changelog Mar 7, 2017
LICENSE Added date validators Dec 2, 2013
autoload.php Fixed some issues reported by SensioLabs Feb 27, 2015
phpmd.xml Fixed coding standard violations, added PHPCS to Travis Feb 24, 2017 Added php7 ready badge Jan 25, 2017

#Sirius Validation

Source Code Latest Version Software License Build Status PHP 7 ready Coverage Status Quality Score Total Downloads

Sirius Validation is a library for data validation. It offers:

  1. validator object
  2. 45 build-in validation rules. There are validators for strings, array, numbers, emails, URLs, files and uploads
  3. validation helper to simplify the validation of single values

Out-of-the-box, the library can handle arrays, ArrayObjects and objects that have implemented the toArray method. In order to validate other data containers you must create a DataWrapper so that the validator be able to extract data from your object.

##Elevator pitch

$validator = new \Sirius\Validation\Validator;

// add a validation rule
$validator->add('title', 'required');

// add a rule that has a list of options
$validator->add('title', 'length', array('min' => 10, 'max' => 100));
// or use JSON
$validator->add('title', 'length', '{"min": 10, "max": 100}');
// or a URL query string
$validator->add('title', 'length', 'min=10&max=100');
// or, if you know that the validator can CORECTLY parse (ie: understand) the options string
$validator->add('title', 'length', '10,100');

// add a rule with a custom error message
$validator->add('title', 'maxlength', 'max=100', 'Article title must have less than {max} characters');

// add a rule with a custom message and a label (very handy with forms)
$validator->add('title:Title', 'maxlength', 'max=100', '{label} must have less than {max} characters');

// add all of rule's configuration in a string (you'll see later why it's handy')
$validator->add('title:Title', 'maxlength(max=255)({label} must have less than {max} characters)');

// add multiple rules at once (separate using [space][pipe][space])
$validator->add('title:Title', 'required | maxlength(255) | minlength(min=10)');

// add all your rules at once
    'title:Title' => 'required | maxlength(100)({label} must have less than {max} characters)',
	'content:Content' => 'required',
	'source:Source' => 'website'

// add nested rules
$validator->add('recipients[*]:Recipients', 'email'); //all recipients must be valid email addresses
$validator->add('shipping_address[city]:City', 'MyApp\Validator\City'); // uses a custom validator to validate the shipping city


##Known issues

In PHP 5.3 there is some problem with the SplObject storage that prevents the library to remove validation rules. This means that in PHP 5.3, you cannot remove a validation rule from a Validator or ValueValidator object

You can’t perform that action at this time.