1. Go to this page and download the library: Download crysalead/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/ */
$v = new Validator();
$v->set('zeroToNine', '/^[0-9]$/');
Validator::messages([
'zeroToNine' => 'must be between 0 to 9'
]);
$v->rule('checksum', 'zeroToNine');
$v->validate(['checksum' => '25']);
$v->errors(); // returns ['zeroToNine' => ['must be between 0 to 9']]
Checker::set('zeroToNine', '/^[0-9]$/');
Checker::message('zeroToNine', 'must be between 0 to 9');
$v = new Validator();
$v->rule('checksum', 'zeroToNine');
$v->validate(['checksum' => '25']);
$v->errors(); // returns ['zeroToNine' => ['must be between 0 to 9']]
$v = new Validator();
$v->rule('title', [
'not:empty' => [
'message' => 'please enter a {:label}',
'label' => 'title'
],
'lengthBetween' => [
'min' => 3,
'max' => 20,
'message' => 'must be between {:min} and {:max} character long'
]
]);
$v = new Validator([
'error' => function($name, $options, $meta = []) {
$message = __t($options['message'] ?: $name); // <- put here your logic to perform translations
return Text::insert($message, $options);
}
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.