Validates a Phoneme element.

@param Phoneme $phoneme
@throws InvalidAttributeValueException
488687
protected function validatePhoneme(Phoneme $phoneme)
    {
        $alphabet = $phoneme->alphabet;
        if (!in_array($alphabet, self::PHONEME_ALPHABETS, true)) {
            throw new InvalidAttributeValueException(
                $phoneme, 'alphabet', $alphabet, self::PHONEME_ALPHABETS, 'alexa'
            );
        }
    }
976274
public function removePhone(PhoneInterface $phone)
    {
        if (!$this->hasPhone($phone)) {
            throw new \InvalidArgumentException('Trying to remove a phone that does not belong to this contact');
        }

        $this->phones->removeElement($phone);

        if ($phone === $this->defaultPhone) {
            if ($this->phones->count() > 0) {
                $this->defaultPhone = $this->phones->first();

                return;
            }

            $this->defaultPhone = null;
        }
    }
1079454
protected function validateAttribute($object,$attribute)
	{
		if(!$this->setOnEmpty)
			$object->$attribute=$this->value;
		else
		{
			$value=$object->$attribute;
			if($value===null || $value==='')
				$object->$attribute=$this->value;
		}
	}
564679
public function validate(MethodInterface $method)
    {
        $constraints = $method->getValidationConstraints();
        if (empty($constraints)) {
            return;
        }

        $violations = $this->validator->validate(
            $method->getAttributes(),
            $constraints
        );

        $countable = is_array($violations) || $violations instanceof \Countable;

        if ($countable && count($violations) !== 0) {
            throw new Exception\InvalidAttributeValue(
                'Your method contains invalid attribute value',
                $violations
            );
        }
    }
1293388
private function validate($content, $locale)
    {
        $validation = $this->markupParser->validate($content, $locale);

        $regex = sprintf(self::INVALID_REGEX, $this->markupNamespace, $this->markupNamespace);
        foreach ($validation as $tag => $state) {
            if (false === strpos($tag, 'sulu-validation-state="' . $state . '"')) {
                $newTag = preg_replace($regex, '$1 sulu-validation-state="' . $state . '"$2', $tag);
                $content = str_replace($tag, $newTag, $content);
            }
        }

        return $content;
    }
65802
public function validate($value): void
    {
        if (in_array($value, $this->values)) {
            return;
        }

        throw new Exception\Invalid(
            $value,
            "Invalid value, expected one of " . implode(",", $this->valuesString())
        );
    }
60434
public function validateAttribute($model, $attribute)
    {
        $value = $model->$attribute;
        $result = $this->validateValue($value);

        if (!empty($result)) {
            $this->addError($model, $attribute, $this->renderMessage($model, $attribute));
        }
    }
117666
public static function validate($phone, $region = 'RU')
    {
        try {
            return self::phoneUtil()->isValidNumberForRegion(self::phoneUtil()->parse($phone, $region), $region);
        } catch (NumberParseException $e) {
            return false;
        }
    }
960544
public static function validateElement(array $element, FormStateInterface $form_state) {
    if ($element['#required'] && $element['#value'] == '_none') {
      $form_state->setError($element, t('@name field is required.', ['@name' => $element['#title']]));
    }

    // Save the value in the element key_column.
    // Note: there is only one item because the field is not multiple value.
    $items = [$element['#key_column'] => $element['#value']];

    $form_state->setValueForElement($element, $items);
  }
1314258
public function setValueAttribute($value)
    {
        if (!$this->isValid($value)) {
            throw new InvalidValueException("The value in the field '" . get_class($this) . "' is invalid");
        }

        $this->attributes['value'] = $this->prepareValue($value);
    }
67316
public function set ($name, $val, $validate = TRUE)
	{
		
		// If the attribute doesn't exists
		
		if (!$this->attributeExists ($name))
		{
			throw new Exception (get_called_class () . '->' . $name . ' attribute does not exist!');
		}
		
		// If attribute setter isn't set or is disabled
		
		if (!$this->attributeSet ($name))
		{
			throw new Exception (get_called_class () . '->' . $name . ' attribute set is disabled!');
		}
		
		// If we're validating the value
		
		if ($validate)
		{
			
			// Set friendly name if one exists
			
			$friendlyName	= isset (static::$attributes[$name]['name'])? static::$attributes[$name]['name'] : $name;
			
			// Validate it using the parser method
			
			$this->parser->Validate ($friendlyName, static::$attributes[$name], $val);
			
		}
		
		// Set the attribute value
		
		$this->attributeValues[$name]	= $val;
		
	}
1309141
public function onBeforeValidate($event)
    {
        /** @var PhoneNumberValidator $validator */
        $validator = \Yii::createObject([
            'class' => PhoneNumberValidator::className(),
            'defaultRegion' => $this->defaultRegion,
        ]);
        foreach ($this->attributes as $localAttribute => $dbAttribute) {
            if ($this->isLocalValueAssigned($localAttribute))
                $validator->validateAttribute($this->owner, $localAttribute);
        }
    }
72415
protected function checkValue(): void
    {
        if (!ctype_digit($this->value) && !is_numeric($this->value) && !empty($this->value)) {
            throw new InvalidArgumentException('NumericParser: Value must be of type numeric');
        }
    }
1238195
private function validate($key, $value) {
    if ($this->keyValidation) {
      $cb = $this->keyValidation;
      $cb($key);
    }
    if ($this->valueValidation) {
      $cb = $this->valueValidation;
      $cb($value);
    }
  }
1014511
private function validate()
    {
        $required = '';

        $validations = [
            'FirstnameOrLastname',
            'PhoneCellphoneOrEmail',
            'ContactTypeId',
            'BusinessTypeId',
            'SuboriginId',
        ];

        for ($i = 0; $i < count($validations) && empty($required); $i++) {
            $required = $this->{"validate" . $validations[$i]}();
        }

        if (!empty($required)) {
            throw new InvalidArgumentException(
                sprintf('Missing required value: %s.', $required)
            );
        }
    }
618132
private static function validateRegExp(string $regExp, string $displayName): void
    {
        /** @uses convertErrorToException() */
        set_error_handler([__CLASS__, 'convertErrorToException'], E_WARNING);
        try {
            if (false === preg_match($regExp, null)) {
                throw new \InvalidArgumentException(
                    "PCRE error in $displayName RegExp: $regExp",
                    preg_last_error()
                );
            }
        } catch (\ErrorException $e) {
            throw new \InvalidArgumentException(
                "PCRE error in $displayName RegExp: " . $e->getMessage() . "; RegExp: $regExp",
                preg_last_error(),
                $e
            );
        } finally {
            restore_error_handler();
        }
    }
228325
public function setPhoneNumber(PhoneNumber $phoneNumber)
    {
        if (!is_a($phoneNumber, PhoneNumber::class, false))
        {
            throw new InvalidArgumentException("The phone number is not an instance of the PhoneNumber class.");
        }

        $this->phoneNumbers[$phoneNumber->getType()] = $phoneNumber;
    }