1. Go to this page and download the library: Download webiik/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/ */
webiik / validator example snippets
$validator = new \Webiik\Validator\Validator();
// Add input to validate and input validation rules
$validator->addInput('meow', function () {
return [
new \Webiik\Validator\Rules\StrLenMin(5, 'Err: Input is shorter than 5 chars.'),
new \Webiik\Validator\Rules\StrLenMax(10, 'Err: Input is longer than 10 chars.'),
];
}, 'greeting');
// Validate all inputs and eventually get array of all invalid inputs
$invalid = $validator->validate(); // Array ( [greeting] => Array ( [0] => Err: Input is shorter than 5 chars. ) )
$validator->addInput('meow', function () {
return [
new \Webiik\Validator\Rules\StrLenMin(5, 'Err: Input is shorter than 5 chars.'),
new \Webiik\Validator\Rules\StrLenMax(10, 'Err: Input is longer than 10 chars.'),
];
}, 'greeting', true);
// Check if input is === $val
Equal($val, string $errMsg = '')
// Check if input is >= $min and <= $max
IntVal(int $min, int $max, string $errMsg = '')
// Check if input is <= $max
IntValMax(int $max, string $errMsg = '')
// Check if input is >= $min
IntValMin(int $max, string $errMsg = '')
// Check if input is email address
isEmail(string $errMsg = '')
// Check if input is_float()
isFloat(string $errMsg = '')
// Check if input is_int()
isInt(string $errMsg = '')
// Check if input is_numeric()
isNumeric(string $errMsg = '')
// Check if input is_object()
isObject(string $errMsg = '')
// Check if input is not empty
isPresent(string $errMsg = '')
// Check if input is_string()
isString(string $errMsg = '')
// Check if input passes FILTER_VALIDATE_URL
isUrl(string $errMsg = '')