PHP code example of nicdamours / validator

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

    

nicdamours / validator example snippets


    $myObject = [
        'name' => 'John Doe',
        'age' => 26,
        'isAdult' => true,
        'email' => '[email protected]',
        'birthdate' => '1990-01-01'
    ];
    
    return Validator::make($myObject)
                        ->name('name')
                        ->int('age')
                        ->boolean('isAdult')
                        ->email('email')
                        ->date('birthDate')
                        ->validate();

    $myObject = [
        'name' => 'John Doe',
        'age' => null,
        'isAdult' => true,
        'email' => '[email protected]',
        'birthdate' => '1990-01-01'
    ];
    
    return Validator::make($myObject)
                        ->name('name', false) // this cannot be null.
                        ->int('age')
                        ->boolean('isAdult',  false) // this cannot be null.
                        ->email('email',  false) // this cannot be null.
                        ->date('birthDate',  false) // this cannot be null.
                        ->validate();