public function add($name, $options = null, $messageTemplate = null, $label = null)
    {
        if (is_array($name) && !is_callable($name)) {
            return $this->addMultiple($name);
        }
        if (is_string($name)) {
            // rule was supplied like 'required | email'
            if (strpos($name, ' | ') !== false) {
                return $this->addMultiple(explode(' | ', $name));
            }
            // rule was supplied like this 'length(2,10)(error message template)(label)'
            if (strpos($name, '(') !== false) {
                list($name, $options, $messageTemplate, $label) = $this->parseRule($name);
            }
        }

        // check for the default label
        if (!$label && $this->label) {
            $label = $this->label;
        }

        $validator = $this->ruleFactory->createRule($name, $options, $messageTemplate, $label);

        return $this->addRule($validator);
    }
public function add($name, $options = null, $messageTemplate = null, $label = null)
    {
        if (is_array($name) && !is_callable($name)) {
            return $this->addMultiple($name);
        }
        if (is_string($name)) {
            // rule was supplied like 'required | email'
            if (strpos($name, ' | ') !== false) {
                return $this->addMultiple(explode(' | ', $name));
            }
            // rule was supplied like this 'length(2,10)(error message template)(label)'
            if (strpos($name, '(') !== false) {
                list($name, $options, $messageTemplate, $label) = $this->parseRule($name);
            }
        }

        // check for the default label
        if (!$label && $this->label) {
            $label = $this->label;
        }

        $validator = $this->ruleFactory->createRule($name, $options, $messageTemplate, $label);

        return $this->addRule($validator);
    }
public function add ( $ name , $ options = null , $ messageTemplate = null , $ label = null ) { if ( is_array ( $ name ) && ! is_callable ( $ name ) ) { return $ this -> addMultiple ( $ name ) ; } if ( is_string ( $ name ) ) { // rule was supplied like 'required | email' if ( strpos ( $ name , ' | ' ) !== false ) { return $ this -> addMultiple ( explode ( ' | ' , $ name ) ) ; } // rule was supplied like this 'length(2,10)(error message template)(label)' if ( strpos ( $ name , '(' ) !== false ) { list ( $ name , $ options , $ messageTemplate , $ label ) = $ this -> parseRule ( $ name ) ; } } // check for the default label if ( ! $ label && $ this -> label ) { $ label = $ this -> label ; } $ validator = $ this -> ruleFactory -> createRule ( $ name , $ options , $ messageTemplate , $ label ) ; return $ this -> addRule ( $ validator ) ; }
Add 1 or more validation rules

@example
// add multiple rules at once
$validator->add(array(
'required',
array('required', array('email', null, '{label} must be an email', 'Field B')),
));

// add multiple rules using a string
$validator->add('required | email');

// add validator with options
$validator->add('minlength', array('min' => 2), '{label} should have at least {min} characters', 'Field label');

// add validator with string and parameters as JSON string
$validator->add('minlength({"min": 2})({label} should have at least {min} characters)(Field label)');

// add validator with string and parameters as query string
$validator->add('minlength(min=2)({label} should have at least {min} characters)(Field label)');

@param string|callback $name
@param string|array $options
@param string $messageTemplate
@param string $label

@return ValueValidator
Add 1 or more validation rules