PHP code example of ideaglory / validation

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

    

ideaglory / validation example snippets


$data = [
    'name' => 'John_Doe',
    'emails' => ['email' => '[email protected]', 'email_confirm' => '[email protected]'],
    'age' => 25,
    'active' => true,
    'website' => 'https://ideaglory.com',
    'birthdate' => '1999-12-31',
    'category' => 'technology',
    'status' => 'inactive',
    'first_name' => 'John',
    'last_name' => 'Doe', 
];

$validate = new Validation($data);

$validate->setDefaults([
    'age' => 30,
    'status' => 'active'
]);

$validate->setRules([
    'name' => ', max 20 chars
]);

$validate->setMessages([
    'name.e at least 18.',
    'age.max' => 'The age must not exceed 60.',
    'active.name is mandatory.',
    'first_name.alpha' => 'The first name must contain only alphabetic characters.',
    'last_name.

$data = ['username' => 'JohnDoe'];
$validate = new Validation($data);
$validate->setRules([
    'username' => '));
}

  Array ( [username] => JohnDoe )
  

  Array ( [username] => Array ( [0] => username must be at least 3 characters. ) )
  

$data = ['age' => 20];
$validate = new Validation($data);
$validate->setRules([
    'age' => 'validate->errors());
}

  Array ( [age] => 20 )
  

$data = ['email' => '[email protected]'];
$validate = new Validation($data);
$validate->setRules([
    'email' => '

  Array ( [email] => [email protected] )
  

  Array ( [email] => Array ( [0] => email must be a valid email. ) )
  

$data = ['number' => 8];
$validate = new Validation($data);
$validate->setRules([
    'number' => 'alidate->validate()) {
    print_r($validate->sanitized());
} else {
    print_r($validate->errors());
}

  Array ( [number] => 8 )
  

  Array ( [number] => Array ( [0] => number validation failed. ) )
  

$data = ['name' => 'John'];
$validate = new Validation($data);
$validate->setDefaults([
    'age' => 25,
    'country' => 'USA'
]);

$validate->setRules([
    'name' => 'rrors());
}

  Array ( [name] => John [age] => 25 [country] => USA )
  

$data = [
    'username' => '   John Doe   ',
    'bio' => '<script>alert("XSS")</script>'
];

$validate = new Validation($data);
$validate->setRules([
    'username' => '

  Array ( [username] => John Doe [bio] => &lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt; )
  

$data = [
    'address' => [
        'city' => 'New York',
        'zip' => '10001'
    ]
];

$validate = new Validation($data);
$validate->setRules([
    'address.city' => '
}

  Array ( [address] => Array ( [city] => New York [zip] => 10001 ) )