cledilsonweb/lontra-validator

PHP data validators and extra validators for Laminas Framework(getlaminas.org)

0.2.1 2022-04-18 20:56 UTC

This package is auto-updated.

Last update: 2024-04-19 01:15:45 UTC


README

Latest Version on Packagist Software License Total Downloads

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

Dependencies

lontra-validator depends on laminas-validator (and suggested(but not required) laminas-db to compare with the database), maintained by the Linux Foundation

Install

Via Composer

$ composer require cledilsonweb/lontra-validator

Usage

$validator = new DateBetween([
    'max' => '2020-10-10', 
    'min' => '2020-05-05', 
    'format' => 'Y-m-d', 
    'inclusive' => true
]);
echo $validator->isValid('2020-06-06'); //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
                ]
            ]
        ]
    ]
);

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

To run the integration test, you need to enable extension=pdo_sqlite

Suggestions and Security

If you discover any security related issues or have any suggestions, please create a new issue.

Credits

License

The MIT License (MIT). Please see License File for more information.