validate

@return  ValidateResult
544368
public function validate()
    {
        $result = new ValidateResult();

        if ($this->get('disabled')) {
            return $result;
        }

        if ($this->required && !$this->checkRequired()) {
            return $result->setMessage(sprintf('Field %s value not allow empty.', $this->getLabel()))
                ->setResult(ValidateResult::STATUS_REQUIRED)
                ->setField($this);
        }

        if ($this->value !== null && $this->value !== '' && $this->validator && !$this->checkRule()) {
            return $result->setMessage(sprintf('Field %s validate fail.', $this->getLabel()))
                ->setResult(ValidateResult::STATUS_FAILURE)
                ->setField($this);
        }

        return $result;
    }
1151078
public function validate()
    {
        $globalValid = false;
        $localValid  = $this->validateOwner();
        foreach ($this->chainedRules as $item) {
            foreach ($item as $multiplier) {
                if (!($localValid = $localValid && $multiplier->validate())) {
                    break;
                }
            }
            if ($globalValid = $globalValid || $localValid) {
                break;
            }
            $localValid = true;
        }
        $globalValid or $this->setOwnerError();
        return $globalValid;
    }
369459
public function validate()
    {
        foreach ($this->inputValidations as $name => $data) {
            $validator = $data['callback'];
            $result = $validator($this);
            if ($result === false) {
                $this->logDebug("Validation FAILED: $name");
                $onError = $data['soundOnError'];
                if (is_array($onError)) {
                    foreach ($onError as $msg) {
                        $this->addPrePromptMessage($msg);
                    }
                } elseif (is_string($onError)) {
                    $this->addPrePromptMessage($onError);
                } else {
                    $this->logDebug("Ignoring validation sound: " . print_r($onError, true));
                }
                return false;
            }
            $this->logDebug("Validation OK: $name");
        }
        return true;
    }
192421
public function validate(EiField $eiField, EiFieldValidationResult $validationResult) {
		return $this->validatable->validateEiFieldValue($this->eiu, $eiField->getValue(), $validationResult);
	}
998162
protected function validate() {
        $validator=parent::validate();
        
        //Verify we have a KapostRefID
        $kapostID=$this->KapostRefID;
        if(empty($kapostID)) {
            $validator->error(_t('KapostObject.MISSING_KAPOST_ID', '_Kapost Reference ID is missing'), 'missing-kapost-id');
        }
        
        return $validator;
    }
492192
public function validateValue($value) {
        $validationResultSet = new ValidationResultSet();
        foreach($this->validators as $validator) {
            $validationResultSet->add($validator->validate($value));
        }
        return $validationResultSet;
    }
967633
public function validate()
    {
        $valid = true;
        $message = null;
        $type = $this->Type;

        // Check if empty strings
        switch ($type) {
            case 'URL':
            case 'Email':
            case 'Phone':
                if ($this->{$type} == '') {
                    $valid = false;
                    $message = _t(
                        __CLASS__ . '.VALIDATIONERROR_EMPTY'.strtoupper($type),
                        'You must enter a {TypeLabel}',
                        [
                            'TypeLabel' => $this->TypeLabel
                        ]
                    );
                }
                break;
            case 'File':
            case 'SiteTree':
                if ($type && empty($this->{$type.'ID'})) {
                    $valid = false;
                    $message = _t(
                        __CLASS__ . '.VALIDATIONERROR_OBJECT',
                        'Please select a {TypeLabel}',
                        [
                            'TypeLabel' => $this->TypeLabel
                        ]
                    );
                }
                break;
        }
        // if its already failed don't bother checking the rest
        if ($valid) {
            switch ($type) {
                case 'URL':
                    $allowedFirst = ['#', '/'];
                    if (!in_array(substr($this->URL, 0, 1), $allowedFirst) && !filter_var($this->URL, FILTER_VALIDATE_URL)) {
                        $valid = false;
                        $message = _t(
                            __CLASS__ . '.VALIDATIONERROR_VALIDURL',
                            'Please enter a valid URL.  Be sure to include http:// for an external URL. or begin your internal url/anchor with a "/" character'
                        );
                    }
                    break;
                case 'Email':
                    if (!filter_var($this->Email, FILTER_VALIDATE_EMAIL)) {
                        $valid = false;
                        $message = _t(
                            __CLASS__ . '.VALIDATIONERROR_VALIDEMAIL',
                            'Please enter a valid Email address'
                        );
                    }
                    break;
                case 'Phone':
                    if (!preg_match("/^\+?[0-9a-zA-Z\-\s]*[\,\#]?[0-9\-\s]*$/", $this->Phone)) {
                        $valid = false;
                        $message = _t(
                            __CLASS__ . '.VALIDATIONERROR_VALIDPHONE',
                            'Please enter a valid Phone number'
                        );
                    }
                    break;
            }
        }

        $result = ValidationResult::create();
        if (!$valid) {
            $result->addError($message);
        }

        $this->extend('updateValidate', $result);

        return $result;
    }
700362
public function validate($data = null)
    {
        if ($data !== null) {
            $this->setData($data);
        }
        // data was already validated, return the results immediately
        if ($this->wasValidated === true) {
            return $this->wasValidated && count($this->messages) === 0;
        }
        foreach ($this->rules as $selector => $valueValidator) {
            foreach ($this->getDataWrapper()->getItemsBySelector($selector) as $valueIdentifier => $value) {
                /* @var $valueValidator \Sirius\Validation\ValueValidator */
                if (!$valueValidator->validate($value, $valueIdentifier, $this->getDataWrapper())) {
                    foreach ($valueValidator->getMessages() as $message) {
                        $this->addMessage($valueIdentifier, $message);
                    }
                }
            }
        }
        $this->wasValidated = true;

        return $this->wasValidated && count($this->messages) === 0;
    }
1055481
public function validate($value) {
        // Sadly php bug #67167 makes the following lines necessary
        if(is_null($value)) {
            return new ValidationResult(false, 'Not a valid boolean but NULL', self::ERR_NULL);
        }
        if(is_object($value)) {
            return new ValidationResult(false, 'Not a valid boolean but an object', self::ERR_OBJECT);
        }
        
        if(filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)===null) {
            return new ValidationResult(false, 'Not a valid boolean', self::ERR_NOBOOLEAN);
        }        
        return new ValidationResult(true);
    }
1162448
public function validate()
    {
        if (!$this->validationHash) {
            return false;
        }
        $db = Database::connection();
        $row = $db->GetRow("select * from MailValidationHashes where mHash = ? order by mDateGenerated desc limit 1", $this->validationHash);
        if ($row['mvhID'] > 0) {
            // Can't do this even though it's a good idea
            //if ($row['email'] != $this->sender) {
            //	return false;
            //} else {
                return $row['mDateRedeemed'] == 0;
            //}
        }
    }
613355
protected function validate()
    {
        $valid = parent::validate();

        if ($this->CanViewType == 'OnlyTheseUsers' && !$this->ViewerGroups()->count()) {
            $valid->error(
                _t(
                    'DMSDocument.VALIDATIONERROR_NOVIEWERSELECTED',
                    "Selecting 'Only these people' from a viewers list needs at least one group selected."
                )
            );
        }

        if ($this->CanEditType == 'OnlyTheseUsers' && !$this->EditorGroups()->count()) {
            $valid->error(
                _t(
                    'DMSDocument.VALIDATIONERROR_NOEDITORSELECTED',
                    "Selecting 'Only these people' from a editors list needs at least one group selected."
                )
            );
        }

        return $valid;
    }
754459
public function validate()
    {
        $this->shouldValidate = false;

        if (parent::validates()) {
            $this->success = true;
        } else {
            $this->fail();
        }

        return $this;
    }
869532
public function getConfigurationValidationResult()
    {
        if (null === $this->configurationValidationResult
            || $this->lastConfigurationHash !== $this->formObject->getHash()
        ) {
            $configurationObject = $this->getConfigurationObject();
            $this->configurationValidationResult = $this->refreshConfigurationValidationResult($configurationObject);
        }

        return $this->configurationValidationResult;
    }
629225
protected function validateUserEmailInstall()
    {
        if ($this->isExcluded('user.email')) {
            return null;
        }

        $options = $this->options;
        $this->options['parents'] = 'user';
        $result = $this->validateEmail();
        $this->options = $options; // Restore original

        return $result;
    }
867954
public function getSessionValidationResult()
    {
        $resultData = $this->getSession()->get("FormInfo.{$this->FormName()}.result");
        if (isset($resultData)) {
            return unserialize($resultData);
        }
        return null;
    }
720374
public function validated()
    {
        if ($this->invalid()) {
            throw new ValidationException($this);
        }

        $results = [];

        $missingValue = Str::random(10);

        foreach (array_keys($this->getRules()) as $key) {
            $value = data_get($this->getData(), $key, $missingValue);

            if ($value !== $missingValue) {
                Arr::set($results, $key, $value);
            }
        }

        return $results;
    }
181606
public function validate(ValidationResult $validationResult)
    {
        $validator = new SynonymValidator(array(
            'SearchSynonyms',
        ));

        $validator->php(array(
            'SearchSynonyms' => $this->owner->SearchSynonyms
        ));

        $errors = $validator->getErrors();

        if (is_array($errors) || $errors instanceof Traversable) {
            foreach ($errors as $error) {
                $validationResult->addError($error['message']);
            }
        }
    }