Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2022-09-01 (3 days ago) | | Not yet rated by the users | | Total: 49 This week: 14 | | All time: 10,336 This week: 13 |
|
Description | | Author |
This package can validate an array of values with a set of rules.
It provides a base class to validate a set of values passed to the class constructor as an array of values.
Applications can extend this class and pass a specific set of validation rules by passing a given array of validation rules.
A separate validation class implements each validation rule.
The package provides a base type validation class, as well several kinds of validation classes for validating values of types:
- Date and time
- Enumerated values
- Integers
- Strings
- Maximum and minimum limit values
- Regular expressions | |
|
|
Innovation award
Nominee: 1x
Winner: 1x |
|
Details
array-validator
Validates an array of values with a set of validators
Example validator:
class DemoValidator extends ValidatorChain
{
public function __construct()
{
$validators = [
'phone' => [
'required' => true,
'validators' => [
[
'type' => Regexp::class,
//The message attribute changes the default message of the validator
'message' => 'Invalid phone number provided',
'options' => [
'pattern' => '/\+36-\d{2}[-]\d{3}[-]\d{4}\b/'
]
],
[
'type' => IsString::class
]
]
],
'name' => [
'required' => true,
//The Required message attribute changes the default message omitted when a field is required, but is empty or not present
'requiredMessage' => 'This field is required',
'validators' => [
[
'type' => IsString::class
]
]
],
'status' => [
'required' => true,
'validators' => [
[
'type' => IsString::class
],
[
'type' => Enum::class,
'options' => [
'allowedElements' => ['active', 'inactive', 'deleted']
]
]
]
]
];
parent::__construct($validators);
}
}
You can also create a new instance of the KDudas\ArrayValidator\ValidatorChain
with the same parameters in its __construct
as above and call its isValid
method.
If you want to add new validation logic, simply implement the KDudas\ArrayValidator\ValidatorInterface
in a class and it is ready to use.
To perform the validation, simply call the isValid
method on the validator instance. To get validation messages, call the getMessages
method on the ValidatorChain
instance.
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.