PHP code example of ava239 / validator

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

    

ava239 / validator example snippets




use Ava239\Validator\Validator;

$v = new \Ava239\Validator\Validator();

// strings
$schema = $v->$v->()->sizeof(2)->shape([
    'name' => $v->string()->se

// custom validator 
$fn = fn($value, $start) => str_starts_with($value, $start);
$v->addValidator('string', 'startWith', $fn);

$schema = $v->string()->test('startWith', 'H');

$schema->isValid('exlet'); // false
$schema->isValid('Hack'); // true

$v = new \Ava239\Validator\Validator();

$fn = fn($value, $start) => str_starts_with($value, $start);
$v->addValidator('string', 'startWith', $fn);

$schema = $v->string()->test('startWith', 'H');

$schema->shape(
    [
        'name' => $v->string()->
        'surname' => $v->string()->er' => $v->number()->ired()->shape(
                    [
                        'num' => $v->number()->

$fn = fn ($value, $start) => str_starts_with($value, $start);
$v->addValidator('string', 'startWith', $fn, 'test msg {{name}}');
$v->string('test name')->test('startWith', 'H'); 

'_' // shape error
'age.positive' // age field, positive validation error
'name.ort field, series sub-field, ch expected data type it generates error with key "valid"
// it's applied for array, number, string validations
// if this error occurs no further validations will be performed for this field
'passport.sub._' // passport field, "sub" sub-field, shape error
'passport.sub.num.
array()
addValidator($type, $name, $validatorFunction)
array
$name
isValid($data)
array()