From 84fc9498b5c19da2e94459dc3788c3d72d0f2698 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 31 Mar 2016 22:37:42 -0400 Subject: [PATCH] Allow N11 exchange numbers as valid. The previous code and commit (fa3d4a0bb5a25c461b4a42a4dbaf9829ee1afd93) were incorrect about invalid exchange numbers as 1-800-211-4511 is a real phone number. I've also removed a duplicate alternation pattern. Refs #8567 --- lib/Cake/Test/Case/Utility/ValidationTest.php | 4 +--- lib/Cake/Utility/Validation.php | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/ValidationTest.php b/lib/Cake/Test/Case/Utility/ValidationTest.php index 48129c8e1..e3f7f25cd 100644 --- a/lib/Cake/Test/Case/Utility/ValidationTest.php +++ b/lib/Cake/Test/Case/Utility/ValidationTest.php @@ -2161,9 +2161,6 @@ class ValidationTest extends CakeTestCase { $this->assertFalse(Validation::phone('1-(511)-999-9999')); $this->assertFalse(Validation::phone('1-(555)-999-9999')); - // invalid exhange - $this->assertFalse(Validation::phone('1-(222)-511-9999')); - // invalid phone number $this->assertFalse(Validation::phone('1-(222)-555-0199')); $this->assertFalse(Validation::phone('1-(222)-555-0122')); @@ -2186,6 +2183,7 @@ class ValidationTest extends CakeTestCase { $this->assertTrue(Validation::phone('1.(333).333-4444')); $this->assertTrue(Validation::phone('1.(333).333.4444')); $this->assertTrue(Validation::phone('1-333-333-4444')); + $this->assertTrue(Validation::phone('1-800-211-4511')); } /** diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index 056780f68..48bf87147 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -672,7 +672,7 @@ class Validation { // Exchange and 555-XXXX numbers $regex .= '(?!(555(?:\s*(?:[.\-\s]\s*))(01([0-9][0-9])|1212)))'; $regex .= '(?!(555(01([0-9][0-9])|1212)))'; - $regex .= '([2-9]1[02-9]|[2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)'; + $regex .= '([2-9]1[02-9]|[2-9][02-9]1|[2-9][0-9]{2})\s*(?:[.-]\s*)'; // Local number and extension $regex .= '?([0-9]{4})';