PHP code example of infinitypaul / php-validator

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

    

infinitypaul / php-validator example snippets


new Validator([
                'full_name' => 'Edward Paul',
                'email' => '[email protected]'
            ]);


        $validator->setRules([
                'full_name' => ['

    $validator->getErrors();

    if(!$validator->validate()){
        //There is an error
        var_dump($validator->getErrors());
    }else {
        //No Error
        var_dump('Passed');
   }


$validator->setAliases([
           'full_name' => 'Full Name',
           'email' => 'Email Address'
       ]);

$validator =  new Validator([
           'email' => [
               '[email protected]',
               ''
           ]
       ]);

$validator->setRules([
           'email' => [
               '

$validator =  new Validator([
           'user' => [
              [
                  'firstName' => ''
              ],
               [
                   'firstName' => 'Paul'
               ]
           ],
       ]);

$validator->setRules([
           'user.*.firstName' => [
               '

use Infinitypaul\Validator\Rules\Rule;

class Uppercase extends Rule
{
//Determine if the validation rule passes
 public function passes($field, $value, $data): bool
    {
       return strtoupper($value) === $value;
    }
//Get the validation error message.
public function message($field): string
    {
        return $field.' Must Be Uppercase';
    }


}

$validator =  new Validator([
           'name' => 'Edward Paul',
       ]);

$validator->setRules([
           'name' => [
               new Uppercase(),
               'max:5'

           ]
       ]);

$validator =  new Validator([
           'picture' => $_FILES['image']['tmp_name'],
       ]);

$validator->setRules([
        'picture' => 'image'
]);
bash
composer 
 php

    $validator =  new Validator([
                'full_name' => 'Edward Paul',
                'email' => '[email protected]'
            ]);
    
            $validator->setRules([
                'full_name' => ['