Skip to content
Permalink
Browse files

Allow N11 exchange numbers as valid.

The previous code and commit (fa3d4a0)
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
  • Loading branch information...
markstory committed Apr 1, 2016
1 parent 13b9149 commit 84fc9498b5c19da2e94459dc3788c3d72d0f2698
Showing with 2 additions and 4 deletions.
  1. +1 −3 lib/Cake/Test/Case/Utility/ValidationTest.php
  2. +1 −1 lib/Cake/Utility/Validation.php
@@ -2161,9 +2161,6 @@ public function testPhone() {
$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 @@ public function testPhone() {
$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'));
}
/**
@@ -672,7 +672,7 @@ public static function phone($check, $regex = null, $country = 'all') {
// 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})';

0 comments on commit 84fc949

Please sign in to comment.
You can’t perform that action at this time.