particle / validator
Flexible and highly usable validation library with no dependencies.
Installs: 1 243 873
Dependents: 16
Suggesters: 0
Security: 0
Stars: 252
Watchers: 13
Forks: 39
Open Issues: 15
Requires
- php: >=5.4
Requires (Dev)
- byrokrat/checkdigit: ^1.0
- giggsey/libphonenumber-for-php: ^7.2
- phpunit/phpunit: ~4.0
- squizlabs/php_codesniffer: 2.*
Suggests
- byrokrat/checkdigit: If you want to use CreditCard validation rule, this library must be installed.
- giggsey/libphonenumber-for-php: If you want to use Phone validation rule, this library must be installed.
This package is auto-updated.
Last update: 2024-11-13 00:04:07 UTC
README
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 using the command line:
composer require particle/validator
Small usage example
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
- 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
- Fully tested: Scrutinizer
- Zero dependencies
===
Find more information and advanced usage examples at validator.particle-php.com