PHP code example of maer / validator

1. Go to this page and download the library: Download maer/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/ */

    

maer / validator example snippets


$data = [
    'foo' => 'bar',
    'lorem' => [
        'ipsum' => 'loremipsum',
    ]
];

$rules = [
    'foo'         => [') === false) {
    print_r($v->getErrors());
}

class MyRules extends \Maer\Validator\Sets\AbstractSet
{
    public function myRule(mixed $input): string|bool
    {
        if ($input === 'hello-world') {
            return true;
        }

        return "Input must be hello-world";
    }

    public function rules(): array
    {
        return [
            'myNewRule' => [$this, 'myRule'],
        ];
    }
}

$data = [
    'foo' => 'hello-world',
];

$rules = [
    'foo' => ['myNewRule'],
];

$v = new Validator($data, $rules);

// Add ruleset
$v->addSet(new MyRules);