PHP code example of kocal / validator

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

    

kocal / validator example snippets



use Kocal\Validator\Validator;

$rules = ['field' => 'tor($rules);
$validator->validate($data);
$validator->passes(); // true
$validator->fails(); // false
$validator->errors()->toArray(); // returns array of error messages


use Kocal\Validator\Validator;

$validator = new Validator([], 'es');


use Kocal\Validator\Validator;

$validator = new Validator(['field' => 'is_foo']);

$validator->extend('is_foo', function ($attribute, $value, $parameters, $validator) {
    return $value == 'foo';
}, "Le champ :attribute n'est pas égal à 'foo'.");

$validator->validate(['field' => 'not_foo']);