PHP code example of mezuno / php-validator

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

    

mezuno / php-validator example snippets


$rules = [
    'some_field' => IntRules::make()->e(),
];

$rules = [
     'some_integer_field' => IntRules::make()->min(1)->max(3),
];

$rules = [
     'password' => StringRules::make()->min(8)->max(32),
];

$rules = [
     'some_array_field' => ArrayRules::make()->items([
         'some_array_item' => StringRules::make()->

$rules = [
     'some_array_field' => ArrayRules::make()->items([
         'some_nested_array_item' => IntRules::make()->

$rules = [
  'card_barcode' => StringRules::make()->exists(CardRepository::class, 'findByBarcode'),
];

$messages = [
     'field.e custom message for type'
     'field.min' => 'Some custom message for min'
     'field.max' => 'Some custom message for max'
     'field.exists' => 'Some custom message for exists'
     
     'phone_field.phone' => 'Some custom message for phone';
     
     'email_field.email' => 'Some custom message for email';
];

$rules = [
     'product.items.price' => 'Item product[price] 

$rules = [
     'products.nested_items.price' => 'Item products[][price] 
json
{
  "some_array_field": {
    "some_nested_array_item": 2
  }
}
json
{
  "some_another_array_field": [
    {
      "some_nested_array_item": 2
    }
  ]
}
json
{
  "some_another_array_field": [
    {
      "some_nested_array_item": 2
    }
  ]
}
json
{
  "some_array_field": {
    "some_nested_array_item": 2
  }
}