PHP code example of devknown / request-validator

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

    

devknown / request-validator example snippets




$rules = [
    # firstname and lastname must exists
    # they should be alphanumeric
    # atleast 2 characters
    'firstname, lastname' => '  'email'               => 'email|unique:users',

    # must be numeric
    # must exists under 'users' table
    'id'                  => 'numeric|exists:users',
    'age'                 => 'min:16|numeric',
    'info[country]'       => '8(123)456-12-34
    # wrong: +38(123)56-123-56
    # wrong: +39(123)456-12-34
    'phoneMask'           => 'phoneMask:(+38(###)###-##-##)',
    'randNum'             => 'between:1, 10|numeric',

    # the value must be an IP Format
    'ip'                  => 'ip',
    'password'            => 'mail :value: is not unique',
   'elevatorFloor.notIn' => 'Oops',
];

$v = V::make($_POST, $rules, $customMessage);

# for specific field
# you can use below code.
$v->lastname->passes();
$v->lastname->fails();

# if you're