You are here

public static function PhoneInternationalElement::validateNumber in International Phone 8

Same name and namespace in other branches
  1. 8.2 src/Element/PhoneInternationalElement.php \Drupal\phone_international\Element\PhoneInternationalElement::validateNumber()
  2. 3.x src/Element/PhoneInternationalElement.php \Drupal\phone_international\Element\PhoneInternationalElement::validateNumber()

Form element validation handler for #type 'color'.

File

src/Element/PhoneInternationalElement.php, line 44

Class

PhoneInternationalElement
Provides a phone_international form.

Namespace

Drupal\phone_international\Element

Code

public static function validateNumber(&$element, FormStateInterface $form_state, &$complete_form) {
  $value = trim($element['#value']);
  $form_state
    ->setValueForElement($element, $value);
  if ($value !== '' && !Drupal::service('phone_international.validate')
    ->isValidNumber($value)) {
    $form_state
      ->setError($element, t('The %name "%phone_international" is not valid.', [
      '%phone_international' => $value,
      '%name' => $element['#title'],
    ]));
  }
}