The Respect/Validation is a remarkable validation engine specifically designed for PHP. It is equipped with an arsenal of over 150 fully tested validation rules. Respect/Validation allows the creation of complex rules, effectively simplifying tasks such as validating numerical, positive values between 1 to 255. It is also equipped with granularity control for improved reporting and a concrete API for non-fluent usage.
Using Respect/Validation in your PHP scripts is quite a straightforward process. First, you need to install it via Composer. You can do that by running the following command:
composer require respect/validation
Once installed, you can use it in your scripts. For example, to validate if an input is a positive number that falls between 1 to 255:
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
$input = 123;
$validation = v::numericVal()->positive()->between(1, 255)->validate($input);
if ($validation){
echo "Input is valid!";
} else {
echo "Invalid input.";
}
In this code snippet, we're requiring the Composer's autoloader, then using the Respect\Validation\Validator class. We created a rule that checks if $input is a numeric value, which is also positive and falls between 1 and 255.
For more in-depth information and tutorials, you can find the comprehensive Respect/Validation documentation on readthedocs. It provides a detailed guide on how to use the more than 150 validation rules, explains how to contribute to the project, and more.