From 83de70efcf2f4f0f65bb0cf513f7e73927947bea Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 17 Mar 2013 18:14:24 -0400 Subject: [PATCH] Tighten Canadian postal code validation. D, F, I, O, Q, U should not be valid anywhere in a canadian postal code. Fixes #3708 --- lib/Cake/Test/Case/Utility/ValidationTest.php | 4 ++++ lib/Cake/Utility/Validation.php | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/ValidationTest.php b/lib/Cake/Test/Case/Utility/ValidationTest.php index 647e46261..2af075603 100644 --- a/lib/Cake/Test/Case/Utility/ValidationTest.php +++ b/lib/Cake/Test/Case/Utility/ValidationTest.php @@ -2126,6 +2126,10 @@ class ValidationTest extends CakeTestCase { $this->assertFalse(Validation::postal('BAA 0ABC', null, 'ca')); $this->assertFalse(Validation::postal('B2A AABC', null, 'ca')); $this->assertFalse(Validation::postal('B2A 2AB', null, 'ca')); + $this->assertFalse(Validation::postal('K1A 1D1', null, 'ca')); + $this->assertFalse(Validation::postal('K1O 1Q1', null, 'ca')); + $this->assertFalse(Validation::postal('A1A 1U1', null, 'ca')); + $this->assertFalse(Validation::postal('A1F 1B1', null, 'ca')); $this->assertTrue(Validation::postal('X0A 0A2', null, 'ca')); $this->assertTrue(Validation::postal('G4V 4C3', null, 'ca')); diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index 91f828ab5..accd571df 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -646,7 +646,9 @@ class Validation { $regex = '/\\A\\b[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2}\\b\\z/i'; break; case 'ca': - $regex = '/\\A\\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] [0-9][A-Z][0-9]\\b\\z/i'; + $district = '[ABCEGHJKLMNPRSTVYX]'; + $letters = '[ABCEGHJKLMNPRSTVWXYZ]'; + $regex = "/\\A\\b{$district}[0-9]{$letters} [0-9]{$letters}[0-9]\\b\\z/i"; break; case 'it': case 'de':