1. Go to this page and download the library: Download iulyanp/flex-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/ */
array:1 [
"contact" => array:2 [
"address" => array:2 [
"alnum" => ""str, Ion Creanga nr.14 A bl. N2" must contain only letters (a-z), digits (0-9) and ".""
"length" => ""str, Ion Creanga nr.14 A bl. N2" must have a length between 6 and 30"
]
]
]
$validator->disableRulesName();
$validator->validate($array, $rules);
if (!$validator->isValid()) {
var_dump($validator->getErrors());
}
// array:1 [
// "contact" => array:2 [
// "phone" => array:1 [
// 0 => ""07579940094" must have a length lower than 10"
// ]
// "address" => array:2 [
// 0 => ""str, Ion Creanga nr.14 A bl. N2" must contain only letters (a-z), digits (0-9) and ".""
// 1 => ""str, Ion Creanga nr.14 A bl. N2" must have a length between 6 and 30"
// ]
// ]
// ]
$validator->useDotErrorKeys();
$validator->validate($array, $rules);
if (!$validator->isValid()) {
var_dump($validator->getErrors());
}
// array:2 [
// "contact.phone" => array:1 [
// "length" => ""07579940094" must have a length lower than 10"
// ]
// "contact.address" => array:2 [
// "alnum" => ""str, Ion Creanga nr.14 A bl. N2" must contain only letters (a-z), digits (0-9) and ".""
// "length" => ""str, Ion Creanga nr.14 A bl. N2" must have a length between 6 and 30"
// ]
// ]
use Respect\Validation\Validator;
$array = [
'username' => '',
'password' => '',
];
$rules = [
'username' => [
'rules' => Validator::notBlank(),
'group' => 'login'
],
'password' => [
'rules' => Validator::notBlank(),
]
];
$validator = new FlexValidator();
$validator->validate($array, $rules);
// will return
array:2 [
"login" => array:1 [
"username" => array:1 [
"notBlank" => "null must not be blank"
]
]
"password" => array:1 [
"notBlank" => "null must not be blank"
]
]
use Respect\Validation\Validator;
$array = [
'username' => '',
'password' => '',
];
$rules = [
'username' => [
'rules' => Validator::notBlank(),
'group' => 'login'
],
'password' => [
'rules' => Validator::notBlank(),
]
];
$validator = new FlexValidator();
$validator->validate($array, $rules, 'auth');
// will return
array:2 [
"login" => array:1 [
"username" => array:1 [
"notBlank" => "null must not be blank"
]
]
"auth" => array:1 [
"password" => array:1 [
"notBlank" => "null must not be blank"
]
]
]
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.