From 421c833c02a699f2a620a7d1e9d288d04992d53c Mon Sep 17 00:00:00 2001
From: Melissa Miller <miller.2676@osu.edu>
Date: Tue, 18 Dec 2018 14:45:06 -0800
Subject: [PATCH] phone and fax validation complete

---
 src/Form/ModuleConfigurationForm.php | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/Form/ModuleConfigurationForm.php b/src/Form/ModuleConfigurationForm.php
index 66d4b08..caf6075 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.'));
       }
     }
 
-- 
GitLab