Skip to content
Snippets Groups Projects
Commit 421c833c authored by Melissa Miller's avatar Melissa Miller
Browse files

phone and fax validation complete

parent ff7070fd
No related branches found
No related tags found
No related merge requests found
......@@ -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.'));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment