PHP code example of gravity / datas_checker

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

    

gravity / datas_checker example snippets




use Gravity\data_checker;

 

    // NUMBER TEST
$control_tests = [
    "myNumberField" => [
        " = [
    "myDateField" => [
        " [
        "

$control_tests = [
    "myFirstField",
    "mySecondField"
];

$control_tests = [
    "myFirstField" => [
        "      "

$checker = new Data_checker();
$isCorrectdata = $checker->verify($data_to_check, $control_tests);
 



use Gravity\data_checker;

// Can be an array (like $_POST) or an object
$data_to_check =
        [
            "creation_date" => "2015-31-01",
            "first_name" => 4,
            "last_name" => "Paul",
            "id" => "24",
            "ip" => "random string",
            "email" => "tata@test",
            "test" => "random string",
            "captcha" => "4D#I3",
            "password" => "azerty123"
        ];
               
$control_tests =
         [
            "creation_date" => [
                "     "min_length" => 1,
                "error_message" => "the name isn't a word or be lower than 1 characters"
            ],
            "id" => [
                ",
                "string",
                "alias" => "Alias_test"
            ],
            "password" => [
                "
 
var_dump($isCorrectdata);
    
[ 
      0 => 
          [
            'error_message' => 'the creation date isn\'t date or be lower than \'2016-01-01\'',
            'data_eval' => '2015-31-01',
            'data_name' => 'creation_date',
            'test_name' => 'greater_than',
          ],
      1 => 
          [
            'error_message' => 'the firstname isn\'t a word or be lower than 4 characters',
            'data_eval' => 4,
            'data_name' => 'first_name',
            'test_name' => 'string',
          ],
      2 => 
          [
            'error_message' => 'the firstname isn\'t a word or be lower than 4 characters',
            'data_eval' => 4,
            'data_name' => 'first_name',
            'test_name' => 'min_length',
          ],
      3 => 
          [
            'error_message' => 'the ip adress doesn\'t exist or not valid ip address',
            'data_eval' => 'random string',
            'data_name' => 'ip',
            'test_name' => 'ip_address',
          ],
      4 => 
          [
            'error_message' => 'Doesn\'t match the control test EMAIL as excepted',
            'data_eval' => 'tata@test',
            'data_name' => 'email',
            'test_name' => 'email',
          ],
      5 => 
          [
            'error_message' => 'Doesn\'t match the control test ALPHANUMERIC as excepted',
            'data_eval' => '4D#I3',
            'data_name' => 'captcha',
            'test_name' => 'alphanumeric'
          ],
      7 =>
          [
            'error_message' => 'Doesn\'t match the control test NOT_ALPHANUMERIC as excepted',
            'data_eval' => 'azerty123',
            'data_name' => 'password',
            'test_name' => 'not_alphanumeric'
          ],
      6 => 
          [
            'error_message' => 'Doesn\'t match the control test CONTAINS_UPPER as excepted',
            'data_eval' => 'azerty123',
            'data_name' => 'password',
            'test_name' => 'contains_upper',
          ],
      7 => 
          [
            'error_message' => 'Doesn\'t match the control test CONTAINS_SPECIAL_CHARACTER as excepted',
            'data_eval' => 'azerty123',
            'data_name' => 'password',
            'test_name' => 'contains_special_character',
          ]
]