https://github.com/particle-php/Validator
Particle\Validator is a validation library with an extremely clean API which makes validation fun!
https://github.com/particle-php/Validator
Last synced: 3 months ago
JSON representation
Particle\Validator is a validation library with an extremely clean API which makes validation fun!
- Host: GitHub
- URL: https://github.com/particle-php/Validator
- Owner: particle-php
- Created: 2015-03-15T17:36:28.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-12-12T19:37:59.000Z (over 2 years ago)
- Last Synced: 2024-11-07T13:39:55.450Z (8 months ago)
- Language: PHP
- Homepage: http://validator.particle-php.com
- Size: 410 KB
- Stars: 252
- Watchers: 13
- Forks: 39
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
Awesome Lists containing this project
README
[](http://validator.particle-php.com)
===[](https://travis-ci.org/particle-php/Validator)
[](https://packagist.org/packages/particle/validator)
[](https://packagist.org/packages/particle/validator)
[](https://scrutinizer-ci.com/g/particle-php/Validator/?branch=master)
[](https://scrutinizer-ci.com/g/particle-php/Validator/?branch=master)*Particle\Validator* is a very small validation library, with the easiest and most usable API we could possibly create.
## Install
To easily include *Particle\Validator* into your project, install it via [composer](https://getcomposer.org) using the command line:```bash
composer require particle/validator
```## Small usage example
```php
use Particle\Validator\Validator;$v = new Validator;
$v->required('user.first_name')->lengthBetween(2, 50)->alpha();
$v->required('user.last_name')->lengthBetween(2, 50)->alpha();
$v->required('newsletter')->bool();$result = $v->validate([
'user' => [
'first_name' => 'John',
'last_name' => 'D',
],
'newsletter' => true,
]);$result->isValid(); // bool(false).
$result->getMessages();
/**
* array(1) {
* ["user.last_name"]=> array(1) {
* ["Length::TOO_SHORT"]=> string(53) "last_name is too short and must be 2 characters long."
* }
* }
*/
```## Functional features
* Validate an array of data
* Get an array of error messages
* Overwrite the default error messages on rules, or error messages on specific values
* Get the validated values of an array
* Validate different contexts (insert, update, etc.) inheriting validations of the default context
* [A large set of default validation rules](http://validator.particle-php.com/en/latest/rules/)
* Ability to extend the validator to add your own custom rules## Non functional features
* Easy to write (IDE auto-completion for easy development)
* Easy to read (improves peer review)
* Ability to separate controller and view logic
* Fully documented: [validator.particle-php.com](http://validator.particle-php.com)
* Fully tested: [Scrutinizer](https://scrutinizer-ci.com/g/particle-php/Validator/)
* Zero dependencies===
Find more information and advanced usage examples at [validator.particle-php.com](http://validator.particle-php.com)