PHP code example of code-corner / validation
1. Go to this page and download the library: Download code-corner/validation 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/ */
code-corner / validation example snippets
use CodeCorner\Validation\Validation;
Validation::validate([
'name' => 'age' => 'numeric|min:18',
'url' => 'URL',
'phone' => 'phone',
'amount' => 'decimal',
'role' => 'in_array:admin,moderator,user',
'username' => 'unique:users',
'password' => 'nullable|string|min:6',
], [
'name' => 'John Doe',
'email' => '[email protected] ',
'age' => 25,
'url' => 'https://example.com',
'phone' => '+1234567890',
'amount' => 123.45,
'role' => 'admin',
'username' => 'johndoe',
'password' => null,
]);
$errors = Validation::getErrors();
print_r($errors);
Validation::dbConfigure(self::$pdo);
odeCorner\Validation\Validation;
Validation::validate([
'name' => ':`tablename`.`fieldname`,`fieldname`-`value`',
'role' => 'in:`tablename`.`fieldname',
'username' => 'assign:`tablename`.`fieldname`',
], [
'name' => 'John Doe',
'email' => '[email protected] ',
'phone' => '+1234567890',
'role' => 'admin',
'username' => 'johndoe',
]);
$errors = Validation::getErrors();
print_r($errors);
odeCorner\Validation\Validation;
Validation::validate([
'name' => '> 'URL',
'phone' => 'phone',
'amount' => 'decimal',
'role' => 'in_array:admin,moderator,user',
'username' => 'unique:users',
'password' => 'nullable|string|min:6',
], [
'name' => 'John Doe',
'email' => '[email protected] ',
'age' => 25,
'url' => 'https://example.com',
'phone' => '+1234567890',
'amount' => 123.45,
'role' => 'admin',
'username' => 'johndoe',
'password' => null,
]);
$errors = Validation::getErrors();
print_r($errors);