1. Go to this page and download the library: Download blakvghost/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/ */
$data = [
'username' => 'BlakvGhost',
];
$validator = new Validator(
$data,
[
'username' => ' 'string' => 'Votre nom d\'utilisateur doit forcément être une chaîne de caractère',
],
]
);
// For the default language
$validator = new Validator($data, $rules, lang: 'fr');
// CustomPasswordRule.php
namespace YourNameSpace\Rules;
use BlakvGhost\PHPValidator\Contracts\Rule;
class CustomPasswordRule implements Rule
{
protected $field;
public function __construct(protected array $parameters = [])
{
}
public function passes(string $field, $value, array $data): bool
{
$this->field = $field;
// Implement your custom validation logic here
// Example: Check if the password is equal to confirm_password
return $value === $data['confirm_password'];
}
public function message(): string
{
return "Vos deux mot de passes ne sont pas identiques";
}
}
use BlakvGhost\PHPValidator\Validator;
use BlakvGhost\PHPValidator\ValidatorException;
use YourNameSpace\CustomPasswordRule;
// ...
try {
$data = [
'password' => '42',
'confirm_password' => '142',
];
// or
// $data = $_POST;
$validator = new Validator($data, [
'password' => ['
use BlakvGhost\PHPValidator\Validator;
use BlakvGhost\PHPValidator\ValidatorException;
use BlakvGhost\PHPValidator\Mapping\RulesMaped;
use YourNameSpace\CustomPasswordRule;
// Add your rule here using an alias and the full namespace of your custom class
RulesMaped::addRule('c_password', CustomPasswordRule::class);
try {
$data = [
'password' => '42',
'confirm_password' => '142',
];
$validator = new Validator($data, [
'password' => '
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.