Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The lontra-validator is a validator package. It provides an OOP approach.

License

Notifications You must be signed in to change notification settings

cledilsonweb/lontra-validator

Repository files navigation

lontra-validator

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
Validator - This class has tools for using laminas-validator and lontra-validator validations

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
// 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",            
 ]          
 ]
 ]
 ]
 ]
);

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.

About

The lontra-validator is a validator package. It provides an OOP approach.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /