public function PhoneInternationalDefaultWidget::phoneValidate in International Phone 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldWidget/PhoneInternationalDefaultWidget.php \Drupal\phone_international\Plugin\Field\FieldWidget\PhoneInternationalDefaultWidget::phoneValidate()
Validate the international phone field.
Parameters
mixed $element: Return Element.
\Drupal\Core\Form\FormStateInterface $form_state: Return FormStateInterface.
File
- src/
Plugin/ Field/ FieldWidget/ PhoneInternationalDefaultWidget.php, line 71
Class
- PhoneInternationalDefaultWidget
- Plugin implementation of the 'phone_international_widget' widget.
Namespace
Drupal\phone_international\Plugin\Field\FieldWidgetCode
public function phoneValidate($element, FormStateInterface $form_state) {
$value = $form_state
->getValue($element['#parents']);
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'],
]));
}
}