PHP code example of district5 / validatorgroup

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

    

district5 / validatorgroup example snippets


/**
 * Creates a new instance of AuthValidationGroup
 */
public function __construct()
{
    $stringTrim = new StringTrim();

    $this->addField('username', [new StringLength(['min' => 4, 'max' => 254])], [$stringTrim], true);
    $this->addField('password', [new StringLength(['min' => 6, 'max' => 64])], [$stringTrim], true);
    $this->addField('device_id', [new StringLength(['min' => 6, 'max' => 64])], [], true);
}

$request = $app->request();

$vg = new \Project\Validate\Group\AuthAuthValidationGroup();

$handler = new \District5\ValidatorGroup\Handler\JSON($request->getBody());
$valid = $vg->isValid($handler);

$vg->getLastErrorMessage();