Download the PHP package redot/validator without Composer
On this page you can find all versions of the php package redot/validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download redot/validator
More information about redot/validator
Files in redot/validator
Package validator
Short Description Validation framework lets you configure, rather than code, your validation logic.
License MIT
Informations about the package validator
PHP Validator
Validation library lets you configure, rather than code, your validation logic.
Installation
Testing
Usage
After registering the rules that you want to use, you can use the validator like this:
Also, you can validate multiple values at once:
Note that multiple validations return an array of failures rather than a Validator instance.
Btw, you can validate values statically:
Registering rules
The validator came without any registered rules by default. You can add them by using the Validator::addRule()
method.
Also you can load the default rules by using the Validator::loadDefaultRules()
method.
Loading the default rules will register the following rules:
Rule | Description | Parameters |
---|---|---|
alpha |
The value must contain only alphabetic characters. | - |
between |
The value must be between the given min and max. | min: int , max: int |
contains |
The value must contain all the given values. | mixed[] |
doesntContain |
The value must not contain all the given values. | mixed[] |
each |
The value must be an array and each item must pass the given rule. | callable |
email |
The value must be a valid email address. | - |
equal |
The value must be equal to the given value. | mixed |
date |
The value must be a valid date. | - |
max |
The value must be less than or equal to the given value. | int |
min |
The value must be greater than or equal to the given value. | int |
pattern |
The value must match the given pattern. | string |
required |
The value must be present. | - |
string |
The value must be a string. | - |
number |
The value must be a number. | - |
array |
The value must be an array. | - |
You can submit a pull request to add a new rule.
Custom rules
If you have a specific rule you want to use, you can create a class that extends Validator\AbstractRule
and register it.
Custom messages
If you want to customize the error messages, you can use the Validator::setMessages()
method.
Note that you can pass parameters to the message using {x}
placeholders where x
is the index of the parameter.
That's it. Enjoy 👌!