Return validation result

@param  Validator $validator
@return Boolean
973732
public function validate($validator)
    {
        parent::validate($validator);

        // Don't validate empty fields
        if (empty($this->value)) {
            return true;
        }

        // Use the VideoLink object to validate
        $obj = VideoLink::create()->setValue($this->value);

        if (!$obj->getService()) {
            $validator->validationError(
                $this->name,
                _t(__CLASS__ . '.ValidationError', 'Please enter a valid YouTube or Vimeo link'),
                'validation'
            );
            return false;
        }

        return true;
    }
170271
public function validate($validator)
    {
        // get the previous values (could contain comma-delimited list)

        $previous = $value = $this->Value();

        if (is_string($value) && strstr($value, ",")) {
            $value = explode(",", $value);
        }

        // set the value as an array for parent validation

        $this->setValue($value);

        $validated = parent::validate($validator);

        // restore previous value after validation

        $this->setValue($previous);

        return $validated;
    }
1364136
public function validate($validator)
    {
        // Don't validate empty fields
        $this->value = trim($this->value);

        if (empty($this->value)) {
            return true;
        }

        $phone = PhoneNumber::create()->setValue($this->value);

        if (!$phone->Link()) {
            $validator->validationError(
                $this->name,
                _t(__CLASS__ . '.ValidationError', 'Please enter a valid phone number'),
                'validation'
            );
            return false;
        }

        return true;
    }
992987
public function validate($validator)
    {
        // First check if value is numeric
        if ($this->value && $this->isNumeric()) {
            // Convert to a number to check
            $value = $this->value + 0;
            
            if(is_int($value)) {
                return true;
            }
        }
        
        $validator->validationError(
            $this->name,
            _t(
                'Checkout.VALIDATION', '{value} is not a valid number, only whole numbers can be accepted for this field',
                array('value' => $this->value)
            ),
            "validation"
        );
        return false;
    }
91560
public static function validator($validator = null)
    {
        if (func_num_args()) {
            static::$_validators[static::class] = $validator;
            return;
        }
        $self = static::class;
        if (isset(static::$_validators[$self])) {
            return static::$_validators[$self];
        }
        $class = static::$_classes['validator'];
        $validator = static::$_validators[$self] = new $class();
        static::_rules($validator);
        return $validator;
    }
731088
public static function populateValidator(Validator $validator)
	{
		if (static::$provider === null)
		{
			static::setProvider(new FromArray(true, 'validation'));
		}

		return static::$provider->populateValidator($validator);
	}
613107
public function validationWidget(Validator $validator)
    {
        return $validator
            ->requirePresence('title')
            ->add('title', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('block', 'You need to provide a title.'),
                ],
                'length' => [
                    'rule' => ['minLength', 3],
                    'message' => __d('block', 'Title need to be at least 3 characters long.'),
                ],
            ])
            ->requirePresence('description')
            ->add('description', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('block', 'You need to provide a description.'),
                ],
                'length' => [
                    'rule' => ['minLength', 3],
                    'message' => __d('block', 'Description need to be at least 3 characters long.'),
                ],
            ])
            ->add('visibility', 'validVisibility', [
                'rule' => function ($value, $context) {
                    return in_array($value, ['except', 'only', 'php']);
                },
                'message' => __d('block', 'Invalid visibility.'),
            ])
            ->allowEmpty('pages')
            ->add('pages', 'validPHP', [
                'rule' => function ($value, $context) {
                    if (!empty($context['data']['visibility']) && $context['data']['visibility'] === 'php') {
                        return strpos($value, '<?php') !== false && strpos($value, '?>') !== false;
                    }

                    return true;
                },
                'message' => __d('block', 'Invalid PHP code, make sure that tags "<?php" & "?>" are present.')
            ])
            ->requirePresence('handler', 'create', __d('block', 'This field is required.'))
            ->add('handler', 'validHandler', [
                'rule' => 'notBlank',
                'on' => 'create',
                'message' => __d('block', 'Invalid block handler'),
            ]);
    }
366716
public static function isValid($validator, $value)
    {
        /** @var ValidatorInterface $validator */
        $validator = static::create($validator);
        $result = $validator->isValid($value);
        static::$_messages = $validator->getMessages();
        return $result;
    }
1309498
public function setValidator(Validator $validator)
    {
        if ($validator) {
            $this->validator = $validator;
            $this->validator->setForm($this);
        }
        return $this;
    }
564117
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('name', 'create')
            ->notEmpty('name', 'update')
            ->allowEmpty('name', 'create');

        $validator
            ->requirePresence('model', 'create')
            ->notEmpty('model');

        $validator
            ->requirePresence('content', 'create')
            ->notEmpty('content')
            ->isArray('content')
            ->add('content', 'validateSaved', [
                'rule' => function ($value, $context) {
                    return is_array($value) ? array_key_exists('saved', $value) : false;
                },
                'message' => 'Missing required key "saved"'
            ])
            ->add('content', 'validateLatest', [
                'rule' => function ($value, $context) {
                    return is_array($value) ? array_key_exists('latest', $value) : false;
                },
                'message' => 'Missing required key "latest"'
            ]);

        return $validator;
    }
176218
protected function getValidatorInstance(): Validator
    {
        $factory = $this->container->make(ValidationFactory::class);

        if (method_exists($this, 'validator')) {
            $validator = $this->container->call([$this, 'validator'], compact('factory'));
        } else {
            $validator = $this->createDefaultValidator($factory);
        }

        if (method_exists($this, 'withValidator')) {
            $this->withValidator($validator);
        }

        return $validator;
    }
185890
public function validationDefault(Validator $validator)
    {
        return $validator
            ->notEmpty('name', __d('wasabi_core', 'Please enter the name of the language.'))
            ->notEmpty('iso2', __d('wasabi_core', 'Please enter the ISO 639-1 code of the language (e.g. "en").'))
            ->add('iso2', 'lengthBetween', [
                'rule' => ['lengthBetween', 2, 2],
                'message' => __d('wasabi_core', 'The ISO 639-1 code must consist of exactly 2 characters.')
            ])
            ->notEmpty('iso3', __d('wasabi_core', 'Please enter the ISO 639-2/T code of the language (e.g. "eng").'))
            ->add('iso3', 'lengthBetween', [
                'rule' => ['lengthBetween', 3, 3],
                'message' => __d('wasabi_core', 'The ISO 639-2/T code must consist of exactly 3 characters.')
            ])
            ->notEmpty('lang', __d('wasabi_core', 'Please enter the HTML lang code of the language (e.g. "en_US").'))
            ->add('lang', 'lengthBetween', [
                'rule' => ['lengthBetween', 2, 5],
                'message' => __d('wasabi_core', 'The HTML lang code must consist of 2 to 5 characters.')
            ]);
    }
598383
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('filename', 'create')
            ->notEmpty('filename');

        $validator
            ->requirePresence('status', 'create')
            ->notEmpty('status');

        $validator
            ->requirePresence('model_name', 'create')
            ->notEmpty('model_name');

        $validator
            ->requirePresence('attempts', 'create')
            ->notEmpty('attempts');

        $validator
            ->dateTime('trashed')
            ->allowEmpty('trashed');

        $validator
            ->uuid('created_by')
            ->notEmpty('created_by');

        $validator
            ->uuid('modified_by')
            ->notEmpty('modified_by');

        return $validator;
    }
75778
public function validate($validator)
    {
        $this->value = trim($this->value);

        $pattern = '^[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$';

        // Escape delimiter characters.
        $safePattern = str_replace('/', '\\/', $pattern);

        if ($this->value && !preg_match('/' . $safePattern . '/i', $this->value)) {
            $validator->validationError(
                $this->name,
                _t('SilverStripe\\Forms\\EmailField.VALIDATION', 'Please enter an email address'),
                'validation'
            );

            return false;
        }

        return true;
    }
31978
public function validate($validator){
		$name = $this->name;
		
		$postcodeField = $this->fieldPostcode;
		$countryField = $this->fieldCountry;
		$latitudeField = $this->fieldLatitude;
		$longditudeField = $this->fieldLongditude;
		$postcodeField->setValue($_POST[$name]['Postcode']);
		$countryField->setValue($_POST[$name]['Country']);
		$latitudeField->setValue($_POST[$name]['Latitude']);
		$longditudeField->setValue($_POST[$name]['Longditude']);
                
		// Result was unique
		if($latitudeField->Value() != '' && is_numeric($latitudeField->Value()) && $longditudeField->Value() != '' && is_numeric($longditudeField->Value())){
			return true;
		}
		
		// postcode and country are still placeholders
                
		if(trim($postcodeField->Value()) == '' || trim($countryField->Value()) == ''){
			$validator->validationError($name, _t('PostCodeLocationField.VALIDATIONJS', 'Please enter an accurate ZIP and City/Country.'), "validation");
			return false;
		}
                
		if(stristr(trim(_t('PostCodeLocationField.ZIPCODEPLACEHOLDER', 'ZIP/Postcode')), trim($postcodeField->Value())) && stristr(trim(_t('PostCodeLocationField.CITYCOUNTRYPLACEHOLDER', 'City/Country')), trim($countryField->Value()))){
			$validator->validationError($name, _t('PostCodeLocationField.VALIDATIONJS', 'Please enter an accurate ZIP and City/Country.'), "validation");
			return false;
		}

		// fetch result from google (serverside)
		$myPostcode = (stristr(trim(_t('PostCodeLocationField.ZIPCODEPLACEHOLDER', 'ZIP/Postcode')), trim($postcodeField->Value()))) ? '' : trim($postcodeField->Value());
		$myCountry = (stristr(trim(_t('PostCodeLocationField.CITYCOUNTRYPLACEHOLDER', 'City/Country')), trim($countryField->Value()))) ? '' : trim($countryField->Value());

		// Update to v3 API
		$googleUrl = 'https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($myPostcode.', '.$myCountry).'&language='.i18n::get_tinymce_lang();
		if(GoogleMaps::getApiKey()) $googleUrl.= '&key='.GoogleMaps::getApiKey();

		$result = json_decode(file_get_contents($googleUrl), true);

		// if result unique
		if($result['status'] == 'OK' && count($result['results']) == 1){
			$latitudeField->setValue($result['results'][0]['geometry']['location']['lat']);
			$longditudeField->setValue($result['results'][0]['geometry']['location']['lng']);
			return true;
		}else{
			$tmpCounter = 0;
			$tmpLocality = null;
			for($i=0; $i<count($result['results']); $i++){
				// check if type is locality political
				if($result['results'][$i]['types'][0] == 'locality' && $result['results'][$i]['types'][1] == 'political'){
					$tmpLocality = $i;
					$tmpCounter++;
				}
			}

			if($tmpCounter == 1){
				$latitudeField->setValue($result['results'][$tmpLocality]['geometry']['location']['lat']);
				$longditudeField->setValue($result['results'][$tmpLocality]['geometry']['location']['lng']);
				return true;
			}else{
				// result not unique
				$validator->validationError($name, _t('PostCodeLocationField.VALIDATIONUNIQUEJS', 'ZIP and City/Country are not unique, please specify.'), "validation");
				return false;
			}
		}
	}
161624
public function addValidator($validator)
    {
        if (!($validator instanceof ValidatorInterface) && !is_callable($validator)) {
            $validator = ValidatorHelper::create($validator);
        }

        $this->validator->addValidator($validator);

        return $this;
    }
21154
public function validate($validator)
    {
        // Validate currency
        $currencies = $this->getAllowedCurrencies();
        $currency = $this->fieldCurrency->dataValue();
        if ($currency && $currencies && !in_array($currency, $currencies)) {
            $validator->validationError(
                $this->getName(),
                _t(
                    __CLASS__ . '.INVALID_CURRENCY',
                    'Currency {currency} is not in the list of allowed currencies',
                    ['currency' => $currency]
                )
            );
            return false;
        }

        // Field-specific validation
        return $this->fieldAmount->validate($validator) && $this->fieldCurrency->validate($validator);
    }