PHP code example of memcrab / validator

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

    

memcrab / validator example snippets


use Memcrab\Validator\Validator;
use Respect\Validation\Validator as v;

class Auth extends Validator
{

    public function authorization()
    {
        $this
            ->addBodyRule('email', v::email(), 'Email not valid', 400101)
            ->addBodyRule('password', v::length(8, 100), 'Password should be more than 8 symbols', 400102);
    }
}

 declare (strict_types = 1);

use Memcrab\Validator\ValidatorException;

try {
  
  // ... getting request GET($getParramethers) and POST($postParramethers)  ...
  
  $Validator = new Auth($getParramethers, $postParramethers);
  $Validator->authorization();
  $Validator->validate();
  
} catch (ValidatorException $error) {
  // handle validation error
}