1. Go to this page and download the library: Download tnapf/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/ */
tnapf / validation example snippets
use Tnapf\Validation\FilterVar;
use Tnapf\Validation\MaxLength;
use Tnapf\Validation\MinLength;
use Tnapf\Validation\Regex;
use function Tnapf\Validation\validateArray;
$data = [
'name' => 'John Doe$$',
'email' => 'malformed-email'
];
$errors = validateArray([
'name' => [
new Regex('Name must only container letters.', '/^[a-zA-Z ]+$/'),
new MaxLength('Name cannot exceed {max} characters.', 255),
new MinLength('Name is
$errors = validateModel(new class {
#[Regex('Name must only container letters.', '/^[a-zA-Z ]+$/')]
#[MaxLength('Name cannot exceed {max} characters.', 255)]
#[MinLength('Name is 0)]
public string $email;
}, [
'name' => 'John Doe$$',
'email' => 'malformed-email'
]);
var_dump($errors);
// or you can pass in a prefilled object
$model = new class {
#[Regex('Name must only container letters.', '/^[a-zA-Z ]+$/')]
#[MaxLength('Name cannot exceed {max} characters.', 255)]
#[MinLength('Name is 0)]
public string $email;
};
$model->name = 'John Doe$$';
$model->email = 'malformed-email';
$errors = validateModel($model, []);
var_dump($errors);
use function Tnapf\Validation\getValidators;
$validators = getValidators(new class {
#[Regex('Name must only container letters.', '/^[a-zA-Z ]+$/')]
#[MaxLength('Name cannot exceed {max} characters.', 255)]
#[MinLength('Name is
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.