diff --git a/src/Form/ModuleConfigurationForm.php b/src/Form/ModuleConfigurationForm.php index 66d4b08089896e8c8fec03b9718fe2954d2a482b..caf6075ae2682b9ce5f95f3db79a1e8ab340eb7f 100644 --- a/src/Form/ModuleConfigurationForm.php +++ b/src/Form/ModuleConfigurationForm.php @@ -123,14 +123,14 @@ class ModuleConfigurationForm extends ConfigFormBase { $form['contact']['phone'] = array( '#type' => 'tel', '#title' => $this->t('Phone'), - '#description' => $this->t('Main contact phone number for your site.'), + '#description' => $this->t('Main contact phone number for your site – formatted as 555-555-5555'), '#default_value' => $config->get('phone'), ); $form['contact']['fax'] = array( '#type' => 'tel', '#title' => $this->t('Fax'), - '#description' => $this->t('Fax number, if applicable.'), + '#description' => $this->t('Fax number, if applicable – formatted as 555-555-5555'), '#default_value' => $config->get('fax'), ); @@ -261,10 +261,9 @@ class ModuleConfigurationForm extends ConfigFormBase { // phone numbers $phoneNumbers = ['phone', 'fax']; - foreach ($phoneNumbers as $number) { - if (strlen($values[$number]) < 7) { - $form_state->setErrorByName($number, $this->t('The ' . $number . ' number is too short.')); + if (!empty($values[$number]) && !preg_match('/^\d{3}-\d{3}-\d{4}$/i', $values[$number])) { + $form_state->setErrorByName($number, $this->t('The ' . $number . ' number is not a valid phone number or is not in the proper format.')); } }