PHP code example of bitapps / wp-validator

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

    

bitapps / wp-validator example snippets


use BitApps\WPValidator\Validator;

$validator = new Validator;

$data = [
    'first_name' => 'John',
    'last_name' => '',
    'email' => 'email@example',
    'password' => '##112233',
    'confirm_password' => '##112233',
];

$rules = [
    'first_name' => ['

$customMessages = [];

$attributes = [
    'first_name' => 'First Name',
    'last_name' => 'Last Name',
    'email' => 'Email',
];

$validation = $validator->make($data, $rules, $customMessages, $attributes);

if ($validation->fails()) {
    echo "<pre>";
    echo print_r($validation->errors(), true);
    echo "</pre>";
} else {
    echo "Success!";
}



use BitApps\WPValidator\Rule;

class BooleanRule extends Rule
{
    // error message if fails...
    private $message = "The :attribute must be a boolean";

    public function validate($value)
    {
        // validation code here...
        return is_bool($value);
    }

    public function message()
    {
        return $this->message;
    }
}

$rules = [
    'agreed' => ['

$customMessages = [
    'ute cannot contain any numerics',
    'between' => 'The :attribute must be given between :min & :max',
    'size' => 'The account number must consist of :size characters',
];

$customMessages = [
    'first_name' => [
        'xcept letters in the first name',
    ],
    'email' => [
        'email' => 'The provided email is not valid',
    ],
];