PHP code example of wepesi / validation

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

    

wepesi / validation example snippets


    $valid = new \Wepesi\App\Validate();
    $schema = new \Wepesi\App\Schema();
    $source = [];
    $rules = ["name" => $schema->string()->min(3)->max(5)->generate()];    
    $valid->check($source,$rules);

    $source=[
        "name"=>"wepesi",
        "email"=>"[email protected]",
        "link"=>"https://github.com/bim-g/wepesi_validation/",
        "age"=>1
        ];

    // rules 
    $rules=[
        "email"=>$schema->string()->email()->min(9)->max(50)->
    ];

    "email"=>$schema->string()->email()->min(9)->max(50)->ing     : type of the value to be checked should be a string
    // - email      : that string should be an email
    // - min=>9     : the email should have minimum of  9 character
    // - max=>50    : the email should have maximum of 50 characters
    // - 

    $source=[
        "name"=>"wepesi",
        "email"=>"[email protected]",
        "link"=>"https://github.com/bim-g/wepesi_validation/",
        "age"=>1
        ];
    $validate = new \Wepesi\App\Validate();
    $schema = new \Wepesi\App\Schema();
    $rules = [
        "name"=>$schema->any(),
        "email"=>$schema->string()->/ return an array with different related errors

    $rules = [
        "name"=>$schema->any(),
        "email"=>$schema->string()->
        "age"=>$schema->number()->

$schema = [
    "names" => $schema->array()->min(1)->max(10)->string()->generate();
    "ages" => $schema->array()->min(2)->max(5)->number()->generate()
]
// name should be an array and should have a minimum of 1 element and maximum should be 10, each element should be a type string
// ages should be an array and should have a minimum of 2 elements and does not exceed 5, each element should be a type number


$source = [
    "name" =>"wepesi",
    "email" => "[email protected]",    
    "possessions" => [
        "cars" => 2,
        "plane" => 0,
        "houses" => 4,
        "children" => -3,
        "children_name" => ["alfa",3,false,"rachel"],
        "children_age" => [20,"15.7","rachel"],
        "location" => [
            "goma" => "Q.Virunga 08",
            "bukabu" => "Bagira 10",
            "kinshasa" => "matadi kibala 05"
        ]
    ]
];

$rules =[
  "name" => $schema->string()->min(1)->max(10)->rate(),
  "possessions" => $schema->array()->min(1)->max(2)->d()->generate(),
      "houses" => $schema->number()->min(6)->->number()->generate(),
      "location" => $schema->array()->min(2)->structure([
          "goma" => $schema->string()->min(20)->generate(),
          "bukabu" => $schema->string()->min(20)->generate(),
          "kinshasa" => $schema->string()->min(20)->generate(),
      ])->generate()
  ])->generate()
];

$schema->array()->string()->structure([])->generate()