1. Go to this page and download the library: Download laurynasgadl/php-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/ */
laurynasgadl / php-validator example snippets
use Luur\Validator\Validator;
use Luur\Validator\Rules\Concrete\MinRule;
use Luur\Validator\Rules\Concrete\RequiredRule;
use Luur\Validator\Exceptions\ValidationFailed;
$validator = new Validator();
$rules = [
'client_id' => '' => 1234,
'details' => [
'name' => 'John Doe',
],
];
try {
$allParams = $validator->validate($rules, $params);
$validatedParams = $validator->validated();
} catch (ValidationFailed $exception) {
var_dump($exception->getMessage());
}
use Luur\Validator\Rules\AbstractRule;
use Luur\Validator\Validator;
class CustomRule extends AbstractRule {
/**
* @param mixed $value
* @return bool
*/
public function passes($value)
{
return true;
}
}
$validator = new Validator();
$params = ['test' => 123];
$result = $validator->validate([
'test' => new CustomRule(),
], $params);
use Luur\Validator\Rules\AbstractRule;
use Luur\Validator\Validator;
class CustomRule extends AbstractRule {
/**
* @param mixed $value
* @return bool
*/
public function passes($value)
{
return true;
}
}
$validator = new Validator();
$validator->registerRule(CustomRule::getSlug(), CustomRule::class);
$params = ['test' => 123];
$result = $validator->validate([
'test' => 'test',
], $params);
use Luur\Validator\Validator;
$validator = new Validator();
$rules = [
'options.*.key' => 'string|,
],
[
'key' => ['passes'],
'value' => false,
],
],
];
$messages = [
'options.*.key.string' => 'Option key should be a string',
];
$validator->validate($rules, $params, $messages);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.