PHP code example of phpsoftbox / validator

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

    

phpsoftbox / validator example snippets




use PhpSoftBox\Validator\Validator;
use PhpSoftBox\Validator\Rule\StringValidation;
use PhpSoftBox\Validator\Rule\IntValidation;

$validator = new Validator();

$result = $validator->validate(
    data: [
        'name' => 'Alex',
        'age' => 17,
    ],
    rules: [
        'name' => [(new StringValidation())->min(2)->max(50)->

public function filters(): array
{
    return [
        'status'  => [new DefaultFilter('all')],  // нет в запросе → 'all'
        'page'    => [new IntegerFilter(1)],      // нет в запросе → 1
        'comment' => [new TrimFilter()],          // нет в запросе → поля нет
    ];
}

use PhpSoftBox\Validator\ValidationOptions;
use PhpSoftBox\Validator\ValidationStopMode;

$options = new ValidationOptions(stopMode: ValidationStopMode::FIRST_PER_FIELD);