Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Making built-in Canadian postal code validation accept postal codes w…

…ith no spaces. Fixes #289
  • Loading branch information...
commit 104da15a737a13283f827d049beb1d0bea5344d5 1 parent 2c1e6de
@markstory markstory authored
View
2  cake/libs/validation.php
@@ -713,7 +713,7 @@ function postal($check, $regex = null, $country = null) {
$_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':
View
1  cake/tests/cases/libs/validation.test.php
@@ -1928,6 +1928,7 @@ function testPostal() {
$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'));
Please sign in to comment.
Something went wrong with that request. Please try again.