PHP code example of dsheiko / validate

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

    

dsheiko / validate example snippets



use \Dsheiko\Validate;

function login($email, $password)
{
    Validate::contract([
      "email" => [ $email, "IsEmailAddress" ],
      "password" => [ $password, [ "IsString"=> [ "minLength" => 6, "maxLength" => 32, "notEmpty" => true ] ] ],
    ]);
    // do login
}



$params = [
  "email" => "jon#snow.io",
  "password" => "******",
];

Validate::map($params, [
    "email" => ["mandatory", "IsEmailAddress"],
    "password" => ["mandatory", "IsString" => ["minLength" => 6, "maxLength" => 128]],
    "rememberMe" => ["optional", "IsBool" ],
]);