PHP code example of cledilsonweb / lontra-validator

1. Go to this page and download the library: Download cledilsonweb/lontra-validator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cledilsonweb / lontra-validator example snippets


$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

$inputFilter->add(
    [
        'name' => 'input_name',
        '[
            [
                'name' => DateBetween::class
                'options' => [
                    'max' => '2020-10-10',
                    'min' => '2020-05-05',
                    'format' => 'Y-m-d',
                    'inclusive' => true
                ]
            ]
        ]
    ]
);

$inputFilter->add(
    [
        'name' => 'input_name',
        '[
            [
               '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",                        
                    ]                    
                ]
            ]
        ]
    ]
);