PHP code example of awurth / slim-validation
1. Go to this page and download the library: Download awurth/slim-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/ */
awurth / slim-validation example snippets
php
use Awurth\Validator\Validator;
use Respect\Validation\Validator as V;
$validator = Validator::create();
$failures = $validator->validate('Too short', V::notBlank()->length(min: 10));
if (0 !== $failures->count()) {
// Validation failed: display errors
foreach ($failures as $failure) {
echo $failure->getMessage();
}
}
php
use Awurth\Validator\ValidationFailureInterface;
$failures = $validator->validate(/* ... */);
$filteredFailures = $failures->filter(static function (ValidationFailureInterface $failure, int $index): bool {
return $failure->getRuleName() === 'notBlank';
});