Skip to content

Latest commit

 

History

History
executable file
·
34 lines (24 loc) · 865 Bytes

1.2 - Head first example.md

File metadata and controls

executable file
·
34 lines (24 loc) · 865 Bytes

1.2 - Head first example:

use KrisKuiper\Validator\Validator;

$data = [
    'department' => 'office',
    'color' => 'black',
    'programmer' => [
        'name' => 'Morris',
        'email' => '[email protected]'
    ],
];

$validator = new Validator($data);

//Select department and color field and attach rules
$validator->field('department', 'color')->required(false)->isString()->lengthBetween(5, 20);

//Select email field within the programmer array and attach rules
$validator->field('programmer.email')->required()->email()->lengthMax(50);

if($validator->passes()) {
    //Validation passes
}

And this is just the beginning...


Go to the previous section.

Go to the next section.