diff --git a/lib/Cake/Test/Case/Utility/ValidationTest.php b/lib/Cake/Test/Case/Utility/ValidationTest.php index 04d0884e5..a9133676b 100644 --- a/lib/Cake/Test/Case/Utility/ValidationTest.php +++ b/lib/Cake/Test/Case/Utility/ValidationTest.php @@ -2134,9 +2134,6 @@ class ValidationTest extends CakeTestCase { // invalid area-codes $this->assertFalse(Validation::phone('1-(511)-999-9999')); - $this->assertFalse(Validation::phone('1-(379)-999-9999')); - $this->assertFalse(Validation::phone('1-(962)-999-9999')); - $this->assertFalse(Validation::phone('1-(295)-999-9999')); $this->assertFalse(Validation::phone('1-(555)-999-9999')); // invalid exhange @@ -2147,10 +2144,13 @@ class ValidationTest extends CakeTestCase { $this->assertFalse(Validation::phone('1-(222)-555-0122')); // valid phone numbers + $this->assertTrue(Validation::phone('416-428-1234')); $this->assertTrue(Validation::phone('1-(369)-333-4444')); $this->assertTrue(Validation::phone('1-(973)-333-4444')); $this->assertTrue(Validation::phone('1-(313)-555-9999')); $this->assertTrue(Validation::phone('1-(222)-555-0299')); + $this->assertTrue(Validation::phone('508-428-1234')); + $this->assertTrue(Validation::phone('1-(508)-232-9651')); $this->assertTrue(Validation::phone('1 (222) 333 4444')); $this->assertTrue(Validation::phone('+1 (222) 333 4444')); diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index 247930364..cf2811a8d 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -620,11 +620,19 @@ class Validation { case 'all': // includes all NANPA members. // see http://en.wikipedia.org/wiki/North_American_Numbering_Plan#List_of_NANPA_countries_and_territories - $regex = '/^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|3[02-689][0-9]|9[02-57-9][0-9]|[246-8][02-46-8][02-46-9])\s*\)'; - $regex .= '|(55[0-46-9]|5[0-46-9][5]|[0-46-9]55|[2-9]1[02-9]|[2-9][02-8]1|[2-46-9][02-46-8][02-46-9]))\s*(?:[.-]\s*)?)'; - $regex .= '(?!(555(?:\s*(?:[.|\-|\s]\s*))(01([0-9][0-9])|1212)))'; + $regex = '/^(?:(?:\+?1\s*(?:[.-]\s*)?)?'; + + // Area code 555, X11 is not allowed. + $areaCode = '(?![2-9]11)(?!555)([2-9][0-8][0-9])'; + $regex .= '(?:\(\s*' . $areaCode . '\s*\)|' . $areaCode . ')'; + $regex .= '\s*(?:[.-]\s*)?)'; + + // 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*)'; + + // Local number and extension $regex .= '?([0-9]{4})'; $regex .= '(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/'; break;