PHP code example of mortimer333 / validate

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

    

mortimer333 / validate example snippets


  $spec = [
    "set" => [
      "user_id" => [ "int"          , "ID"    ],
      "login"   => [ "string"       , "Login" ],
      "name"    => [ "string_empty" , "Name"  ],       
      "bio"     => [ ["!js","!php" ], "Bio"   ],       
      "add"     => [ "array"        , "Additional", [  
          "set" => [
            "created" => ["types" => "date"]           
          ],
          "free" => ["string","int"]                   
        ]
      ]
    ]
  ];

  $data = [
    "user_id" => 0,
    "login"   => "login",
    "name"    => "name",
    "bio"     => "",
    "add"     => [
      "created" => "2020-01-01",
      "nana",
      "age" => 12
    ]
   ];

  if ( !Vali::dat( $data, $spec ) ) echo Vali::GetError();

  composer 

$spec = [
    "check" => [
      "set" => [
        "type" => [ "string"   , "Type of sent data" ],
        "data" => [ "this.type", "Data"              ]
      ]
    ]
  ];

  $data = [
    "type" => 'int',
    "data" => 'a',
  ];

  if ( !Vali::dat( $data, $spec ) ) echo Vali::GetError(); // output : Data is not a number.