1. Go to this page and download the library: Download biohzrdmx/validator-php 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/ */
biohzrdmx / validator-php example snippets
# Import namespace
use Validator\Validator;
# Create a validator instance and add some rules
$validator = Validator::newInstance()
->addRule('name', $name)
->addRule('email', $email, 'email')
->addRule('password', $password)
->addRule('confirm', $confirm, 'equal', $password)
->validate();
# And check the result
if (! $validator->isValid() ) {
$errors = $validator->getErrors();
foreach ($errors as $error) {
echo $error->message;
}
}
addRule($name, $value, $type = '
$validator->addRule('Name', $name, 'custom', function($value) {
# We do not accept Homers
return $name != 'Homer';
});
class CustomRule extends Rule {
public function check() {
$ret = $name != 'Homer';
if (! $ret ) {
$message = sprintf('We do not accept Homers');
throw new ValidationException($this, $message);
}
return $ret;
}
}