The lontra-validator is a validator package, a complement to laminas-validator, compatible with validation for laminas-form. It provides an OOP approach.
ArrayRecordExists - Check if values in array exists on database
DateBetween - Checks whether the date is between values entered.
DateGreaterThan - Checks if date is greater
DateLessThan - Checks if date is less
EndsWith - If text ends with a value
IsArray - If value is a valid array
Password - Checks whether the entered value is a valid password with the options uppercase, lowercase, number, special characters.
StartsWith - If text starts with a value
WordCount - Validate the number of words in a string
Validator - This class has tools for using laminas-validator and lontra-validator validations
lontra-validator depends on laminas-validator (and suggested(but not required) laminas-db to compare with the database), maintained by the Linux Foundation
Via Composer
$ composer require cledilsonweb/lontra-validator
$validator = new DateBetween([
'max' => '2020-10-10',
'min' => '2020-05-05',
'format' => 'Y-m-d',
'inclusive' => true
]);
echo $validator->isValid('2020-06-06'); //true
// Using static validation
echo Validator::isValid(DateBetween::class, '2020-06-06', ['max' => '2020-10-10', 'min' => '2020-05-05']); //true
// Or
echo Validator::validateDateBetween('2020-06-06', ['max' => '2020-10-10', 'min' => '2020-05-05']); //true
It is possible to use the validator on the Laminas Form with InputFilter
$inputFilter->add(
[
'name' => 'input_name',
'required' => true,
'filters' => // your filters...,
'validators' => [
[
'name' => DateBetween::class
'options' => [
'max' => '2020-10-10',
'min' => '2020-05-05',
'format' => 'Y-m-d',
'inclusive' => true
]
]
]
]
);
To customize the validation message:
$inputFilter->add(
[
'name' => 'input_name',
'required' => true,
'filters' => // your filters...,
'validators' => [
[
'name' => DateGreaterThan::class, 'options' => [
'format' => 'Y-m-d',
'min' => 'now',
'messages' => [
DateGreaterThan::NOT_GREATER_INCLUSIVE => 'A data informada deve ser maior ou igual a data atual', DateGreaterThan::NOT_GREATER => "A data informada deve ser maior que a data atual", DateGreaterThan::IVALID_FORMAT => "A data informada está no formato inválido", DateGreaterThan::IVALID_DATE => "A data informada é inválida",
]
]
]
]
]
);
Please see CHANGELOG for more information on what has changed recently.
$ composer test
To run the integration test, you need to enable extension=pdo_sqlite
If you discover any security related issues or have any suggestions, please create a new issue.
The MIT License (MIT). Please see License File for more information.