PHP code example of morebec / validator

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

    

morebec / validator example snippets



use Morebec\Validator\Rule as Assert;
use Morebec\Validator\Validator;


// Validate a single rule for a given field
Validator::validate($form['email_address'], new Assert\One(
    new Assert\IsString('The email address field was expected to be a string')
));

// Validate Multiple Rules for a given field
Validator::validate($form['email_address'], new Assert\All([
    new Assert\IsString('The email address field was expected to be a string'),
    new Assert\NotBlank('The email address field was expected not to be blank'),
    new Assert\IsEmail('The email address field was expected to be a valid email address'),
]));


// Ensure At least one rule is valid
Validator::validate($form['email_address'], new Assert\AtLeastOne([
    new Assert\IsString('The email address field was expected to be a string'),
    new Assert\NotBlank('The email address field was expected not to be blank'),
    new Assert\IsEmail('The email address field was expected to be a valid email address'),
]));
bash
php vendor/bin/phpunit --bootstrap vendor/autoload.php tests