public function set($name, $rule = null)
    {
        if (!is_array($name)) {
            $name = [$name => $rule];
        }
        $this->_handlers = $name + $this->_handlers;
    }
public function set($name, $rule = null)
    {
        if (!is_array($name)) {
            $name = [$name => $rule];
        }
        $this->_handlers = $name + $this->_handlers;
    }
public function set ( $ name , $ rule = null ) { if ( ! is_array ( $ name ) ) { $ name = [ $ name => $ rule ] ; } $ this -> _handlers = $ name + $ this -> _handlers ; }
Sets one or several validation rules.

For example:
{{{
$validator = new Validator();
$validator->set('zeroToNine', '/^[0-9]$/');
$isValid = $validator->isZeroToNine('5'); // true
$isValid = $validator->isZeroToNine('20'); // false
}}}

Alternatively, the first parameter may be an array of rules expressed as key/value pairs,
as in the following:
{{{
$validator = new Validator();
$validator->set([
'zeroToNine' => '/^[0-9]$/',
'tenToNineteen' => '/^1[0-9]$/',
]);
}}}

In addition to regular expressions, validation rules can also be defined as full anonymous
functions:
{{{
use app\model\Account;

$validator = new Validator();
$validator->set('accountActive', function($value, $options = []) {
$value = is_int($value) ? Account::id($value) : $value;
return (boolean) $value->is_active;
});

$testAccount = Account::create(['is_active' => false]);
$validator->isAccountActive($testAccount); // returns false
}}}

These functions can take up to 3 parameters:
- `$value`  _mixed_ : This is the actual value to be validated (as in the above example).
- `$options` _array_: This parameter allows a validation rule to implement custom options.
- `'format'` _string_: Often, validation rules come in multiple "formats", for example:
postal codes, which vary by country or region. Defining multiple formats allows you to
retain flexibility in how you validate data. In cases where a user's country of origin
is known, the appropriate validation rule may be selected. In cases where it is not
known, the value of `$format` may be `'any'`, which should pass if any format matches.
In cases where validation rule formats are not mutually exclusive, the value may be
`'all'`, in which case all must match.


@param mixed  $name The name of the validation rule (string), or an array of key/value pairs
of names and rules.
@param string $rule If $name is a string, this should be a string regular expression, or a
closure that returns a boolean indicating success. Should be left blank if
`$name` is an array.
Sets one or several validation rules .