From 104da15a737a13283f827d049beb1d0bea5344d5 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 6 Feb 2010 14:20:28 -0500 Subject: [PATCH] Making built-in Canadian postal code validation accept postal codes with no spaces. Fixes #289 --- cake/libs/validation.php | 2 +- cake/tests/cases/libs/validation.test.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cake/libs/validation.php b/cake/libs/validation.php index 6638f6973..09bdbcc5c 100644 --- a/cake/libs/validation.php +++ b/cake/libs/validation.php @@ -713,7 +713,7 @@ class Validation extends Object { $_this->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': - $_this->regex = '/\\A\\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] [0-9][A-Z][0-9]\\b\\z/i'; + $_this->regex = '/\\A\\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] ?[0-9][A-Z][0-9]\\b\\z/i'; break; case 'it': case 'de': diff --git a/cake/tests/cases/libs/validation.test.php b/cake/tests/cases/libs/validation.test.php index 3adb5d38f..ecac28cc2 100644 --- a/cake/tests/cases/libs/validation.test.php +++ b/cake/tests/cases/libs/validation.test.php @@ -1928,6 +1928,7 @@ class ValidationTest extends CakeTestCase { $this->assertFalse(Validation::postal('B2A 2AB', null, 'ca')); $this->assertTrue(Validation::postal('X0A 0A2', null, 'ca')); $this->assertTrue(Validation::postal('G4V 4C3', null, 'ca')); + $this->assertTrue(Validation::postal('L4J8D6', null, 'ca')); $this->assertFalse(Validation::postal('111', null, 'us')); $this->assertFalse(Validation::postal('1111', null, 'us'));