public function validate(Collection $collection = null)
    {
        $this->errors = [];
        foreach ($this->getValuesAsArray() as $index => $value) {
            # skip fields with a null value if they are not required
            if ($value === null && $this->hasRule(Rule::REQUIRED) === false) {
                continue;
            }

            foreach ($this->rules as $name => $rule) {
                $rule->setValue($value);
                $rule->setField($this, $index);
                $rule->setCollection($collection);
                if ($rule->validate() === true) {
                    $fmtValue = $rule->getValue();
                    if ($fmtValue !== $value) {
                        $value = $fmtValue;
                        $this->setValue($fmtValue, $index);
                    }
                }
                else {
                    $this->errors[] = $rule->getError();
                    break;
                }
            }
        }
        return count($this->errors) === 0;
    }
public function validate(Collection $collection = null)
    {
        $this->errors = [];
        foreach ($this->getValuesAsArray() as $index => $value) {
            # skip fields with a null value if they are not required
            if ($value === null && $this->hasRule(Rule::REQUIRED) === false) {
                continue;
            }

            foreach ($this->rules as $name => $rule) {
                $rule->setValue($value);
                $rule->setField($this, $index);
                $rule->setCollection($collection);
                if ($rule->validate() === true) {
                    $fmtValue = $rule->getValue();
                    if ($fmtValue !== $value) {
                        $value = $fmtValue;
                        $this->setValue($fmtValue, $index);
                    }
                }
                else {
                    $this->errors[] = $rule->getError();
                    break;
                }
            }
        }
        return count($this->errors) === 0;
    }
public function validate ( Collection $ collection = null ) { $ this -> errors = [ ] ; foreach ( $ this -> getValuesAsArray ( ) as $ index => $ value ) { # skip fields with a null value if they are not required if ( $ value === null && $ this -> hasRule ( Rule :: REQUIRED ) === false ) { continue ; } foreach ( $ this -> rules as $ name => $ rule ) { $ rule -> setValue ( $ value ) ; $ rule -> setField ( $ this , $ index ) ; $ rule -> setCollection ( $ collection ) ; if ( $ rule -> validate ( ) === true ) { $ fmtValue = $ rule -> getValue ( ) ; if ( $ fmtValue !== $ value ) { $ value = $ fmtValue ; $ this -> setValue ( $ fmtValue , $ index ) ; } } else { $ this -> errors [ ] = $ rule -> getError ( ) ; break ; } } } return count ( $ this -> errors ) === 0 ; }
Validate all the values in the field

@param \sndsgd\field\Collection|null $collection A field collection
@return boolean True if all values are
Validate all the values in the field