1. Go to this page and download the library: Download khalyomede/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/ */
use Khalyomede\Validator;
use Khalyomede\Exception\RuleNotFoundException;
$validator = new Validator([
'name' => ['string']
]);
try {
$validator->validate(['name' => 'John']);
var_dump($validator->failed()); // false
}
catch( RuleNotFoundException $exception ) {
echo "rule {$exception->getRule()} does not exists";
exit(1);
}
use Khalyomede\Validator;
use Khalyomede\Exception\RuleNotFoundException;
$validator = new Validator(['name' => ['Exception $exception ) {
echo "rule {$exception->getRule()} does not exist";
exit(1);
}
use Khalyomede\Validator;
if (Validator::has('ip') === false) {
echo "rule ip does not exist yet";
}
use Khalyomede\Validator;
$validator = new Validator([
'sith' => ['h Maul', 'Darth Vador', 'Darth Sidious']
]);
var_dump( $validator->failed() ) // "false", hm... should have been true after all these guys did but anyway
$validator = new Validator([
'hobbies' => ['array']
]);
$validator = new Validator([
'created_at' => ['date']
]);
$validator = new Validator([
'updated_at' => ['datetime']
]);
$validator = new Validator([
'contact' => ['email']
]);
$validator = new Validator([
'name' => ['filled']
]);
$validator = new Validator([
'age' => ['integer']
]);
$validator = new Validator([
'street' => ['lower']
]);
$validator = new Validator([
'lastname' => ['present']
]);