You are here

public static function PhoneInternationalElement::validateNumber in International Phone 3.x

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

Form element validation handler for #type 'phone_international'.

File

src/Element/PhoneInternationalElement.php, line 56

Class

PhoneInternationalElement
Provides a phone_international form.

Namespace

Drupal\phone_international\Element

Code

public static function validateNumber(&$element, FormStateInterface $form_state, &$complete_form) {
  $value = $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'],
    ]));
  }
}