PHP code example of ongom / php-validator

1. Go to this page and download the library: Download ongom/php-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/ */

    

ongom / php-validator example snippets


->custom(callable $callback, string $errorMessage)

->custom(fn($v) => strlen($v) % 2 === 0, 'Length must be even.')


$errors = Validate::string('Hello123!')
    ->min_length(5)
    ->max_length(10)
    ->uppercase()
    ->lowercase()
    ->has_number()
    ->special_character()
    ->run();

$errors = Validate::number(5.5)
    ->min(0)
    ->max(10)
    ->float()
    ->run();

$errors = Validate::file('image')
    ->min_size(100) // 100KB
    ->max_size(2048) // 2MB
    ->allowed_extension(['jpg', 'png'])
    ->allowed_mime(['image/jpeg', 'image/png'])
    ->run();
Validate::file($key, $source = null, $fieldName = 'File')
$key
$_FILES array
$source
->run()