1. Go to this page and download the library: Download solophp/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/ */
$validator->addCustomRule('even', function ($value, $param, $data) {
return (int)$value % 2 === 0;
});
// Usage
$rules = ['number' => 'even'];
$messages = ['number.even' => 'The number must be even.'];
// Global messages
$messages = [
'ormat.'
];
$validator = new Validator($messages);
// Per-validation messages
$errors = $validator->validate($data, $rules, [
'password.min' => 'Password must be at least 8 characters.'
]);
if ($validator->fails()) {
foreach ($validator->errors() as $field => $messages) {
echo "$field: " . implode(', ', $messages);
}
}
// Default message for 'min' rule:
'The :field must be at least :param characters.'
// Becomes:
'The password must be at least 8 characters.'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.