Skip to content

Commit

Permalink
Merge pull request #150 from davidyell/patch-1
Browse files Browse the repository at this point in the history
[GB] Optional postcode space
  • Loading branch information
dereuromark authored Feb 23, 2017
2 parents 53fb088 + a920919 commit 55ff187
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Validation/GbValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GbValidation extends LocalizedValidation
*/
public static function postal($check)
{
$pattern = '/\\A\\b[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2}\\b\\z/i';
$pattern = '/\\A\\b[A-Z]{1,2}[0-9][A-Z0-9]? ?[0-9][ABD-HJLNP-UW-Z]{2}\\b\\z/i';

return (bool)preg_match($pattern, $check);
}
Expand Down
15 changes: 14 additions & 1 deletion tests/TestCase/Validation/GbValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,20 @@ class GbValidationTest extends TestCase
*/
public function testPostal()
{
$this->assertTrue(GbValidation::postal('DT4 8PP'));
$this->assertFalse(GbValidation::postal('DT4-8PP'));
$this->assertTrue(GbValidation::postal('sp110qn'));
$this->assertTrue(GbValidation::postal('SP110QN'));
$this->assertTrue(GbValidation::postal('DT4 8PP'));
$this->assertTrue(GbValidation::postal('W1A 1AA'));
$this->assertTrue(GbValidation::postal('W12 7TQ'));
$this->assertTrue(GbValidation::postal('SW1A 0AA'));
$this->assertTrue(GbValidation::postal('W1J 7NT'));
$this->assertTrue(GbValidation::postal('EC1A 1BB'));
$this->assertTrue(GbValidation::postal('W1A 0AX'));
$this->assertTrue(GbValidation::postal('M1 1AE'));
$this->assertTrue(GbValidation::postal('B33 8TH'));
$this->assertTrue(GbValidation::postal('CR2 6XH'));
$this->assertTrue(GbValidation::postal('XM45HQ'));
$this->assertFalse(GbValidation::postal('SAN TA1'));
}
}

0 comments on commit 55ff187

Please sign in to comment.