PHP code example of windwalker / validator

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

    

windwalker / validator example snippets


use Windwalker\Validator\ValidatorComposite;

$validator = new ValidatorComposite([
    AlnumValidator::class,
    new PhoneValidator
]);

$validator->validate('1a2b'); // false
$validator->getResults(); // [true, false]

use Windwalker\Validator\ValidatorComposite;

$validator = new ValidatorComposite([
    AlnumValidator::class,
    new PhoneValidator
])->setMode(ValidatorComposite::MODE_MATCH_ONE);

$validator->validate('1a2b'); // true
$validator->getResults(); // [true, false]

$validator->validateOne($value);
$validator->validateAll($value);
 php
use Windwalker\Validator\Rule\EqualsValidator;

$validator = new EqualsValidator('ABC');

$validator->validate('ABC'); // bool(true)
 php
use Windwalker\Validator\AbstractValidator;

class MyValidator extends AbstractValidator
{
	public function test($string)
	{
		return (bool) strlen($string);
	}
}

$validator = new MyValidator;

$validator->validate('foo');