PHP code example of redot / validator

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

    

redot / validator example snippets


use Redot\Validator\Validator;

/* Instantiate a new validator */
$validator = new Validator($email);

/* Or you can use the static method init */
$validator = Validator::init($email);

/* Apply your rules */
$validator->email()->

$errors = Validator::initMultiple($_POST, [
    'email' => 'email',
    'password' => '

$isEmail = Validator::email('[email protected]'); // true

use Redot\Validator\Rules\RequiredRule;

Validator::addRule(RequiredRule::class);

Validator::loadDefaultRules();

class CustomRule extends AbstractRule
{
    protected string $message = '...';

    public function getName(): string
    {
        // name will be used to call the rule
    }

    public function validate(mixed $value, mixed ...$params): bool
    {
        // validation logic
    }
}

Validator::setMessages([
    'not a valid email.',
    'max' => 'The value should be less than or equal to {0}.',
]);