kris-kuiper / validator
Modern PHP validator on steroids for validating forms and/or array's.
Requires
- php: >=8.0
- ext-mbstring: *
Requires (Dev)
- brianium/paratest: ^6.4
- phpro/grumphp: ^1.12
- phpstan/phpstan: ^1.7
- phpunit/phpunit: ^9
- slevomat/coding-standard: ^7.2
- vimeo/psalm: ^4.27
- dev-master
- v1.5.7
- v1.5.6
- v1.5.5
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.10
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-fix-required-with-rule
- dev-feat-advanced-template
- dev-feat-field-resolver
- dev-feat-active-url
- dev-feat-required-array-keys-rule
- dev-feat-nullable-rule
- dev-feat-alpha-space-rule
- dev-feat-prohibited-rules
- dev-feat-extra-rules
- dev-feat-if
- dev-feat-default-values
- dev-feat-rules
- dev-distinct_rule
- dev-documentation
- dev-filter
- dev-events
- dev-built_in_validator
- dev-extra_rules
- dev-logo
- dev-validated_data
- dev-messages
- dev-alias
- dev-storage
- dev-refactor
- dev-accepted_if_rule
- dev-digits_rules
- dev-before_or_equal_rule
- dev-after_or_equal_rule
- dev-code_coverage
- dev-composer
This package is auto-updated.
Last update: 2024-11-12 01:44:04 UTC
README
Introduction
Validating incoming data or array's (i.e. POST data) should not be hard. Meet Modern PHP Validator which does the trick nice, clean and easy.
Here are a couple of the many perks:
- 100+ predefined validation rules;
- 15+ predefined middleware or create your own custom middleware;
- No new syntax you need to learn as in the case with i.e. Laravel Validator. Your editor/IDE can complete every validation rule, custom message, middleware, etc. out of the box;
- Easy retrieving the validated data after validation;
- Combine multiple fields as one for single validation (i.e. day, month, year inputs as a single date field for validation);
- Use validation blueprints to extend other validators for DRY method;
- Define you own validation rules and custom error messages.
Modern PHP Validator provides several approaches to validate your application's (incoming) data. It makes it a breeze to validate form submit values as combining multiple input for single validation. It supports middleware and custom validation rules and error messages. It will also return the validated data to insert the data into i.e. a database.
Installation
Modern PHP Validator is available on Packagist (using semantic versioning). Installation via Composer is the recommended way.
Run:
composer require kris-kuiper/validator
Or add this line to your composer.json file:
"kris-kuiper/validator": "^1.5"
Documentation
All documentation can be found in the docs folder.
Index:
- Intro
- Installation
- Execute validation
- Validation rules
- Custom validation rules
- Conditional rules
- Validation filtering
- Combining
- Errors messages
- Retrieving validated data
- Aliases
- Blueprints
- Middleware
- Default values
- Events
- Storage
- Examples
- License
Validation rules
Below is a list with all predefined validation rules.
Head first example:
use KrisKuiper\Validator\Validator; $data = [ 'department' => 'office', 'color' => 'black', 'programmer' => [ 'name' => 'Morris', 'email' => 'morris@domain.com' ], ]; $validator = new Validator($data); //Select department and color field and attach rules $validator->field('department', 'color')->required(false)->isString()->lengthBetween(5, 20); //Select email field within the programmer array and attach rules $validator->field('programmer.email')->required()->email()->lengthMax(50); if($validator->passes()) { //Validation passes }
And this is just the beginning... Check out the docs for lots of more validation goodies.
License
Modern PHP Validator is open-sourced software licensed under the MIT license.