Skip to content

Commit

Permalink
fix: fr and es shouldn't allow > 5 digits zip code
Browse files Browse the repository at this point in the history
  • Loading branch information
turbo8p committed Oct 7, 2021
1 parent 8943ca9 commit 11ef712
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ZipCode/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class Validator
'DEFAULT' => '[0-9A-Z\-]{1,10}',
'DK' => '\\d{4}',
'EE' => '[1-9]{1}[0-9]{4}',
'ES' => '(AD{0,1}\\d{3})|\\d{5}',
'ES' => '(AD{0,1}\\d{3})|^\\d{5}',
'FI' => '\\d{5}',
'FR' => '(AD{0,1}\\d{3})|\\d{5}',
'FR' => '(AD{0,1}\\d{3})|^\\d{5}',
'GB' => '[A-Z\\d]{2,4}\\s\\d[A-Z]{2}',
'GR' => '[1-9]{1}[0-9]{4}',
'HR' => '[0-9]{5}',
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/ZipCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public function testIsValid()
$this->assertFalse(Validator::isValid('01234', 'RO'), 'RO');
$this->assertFalse(Validator::isValid('20207 MLINI', 'HR'), 'HR');
$this->assertFalse(Validator::isValid('12345678901', 'US'));
$this->assertFalse(Validator::isValid('080024', 'ES'));
$this->assertFalse(Validator::isValid('080024', 'FR'));

$this->assertTrue(Validator::isValid('123456', 'RO'), 'RO');
$this->assertTrue(Validator::isValid('01234', 'FR'), 'FR');
Expand All @@ -25,6 +27,8 @@ public function testIsValid()
$this->assertTrue(Validator::isValid('LV-1111', 'LV'));
$this->assertTrue(Validator::isValid('1111', 'LV'));
$this->assertTrue(Validator::isValid('06093-2227', 'US'));
$this->assertTrue(Validator::isValid('08002', 'ES'));
$this->assertTrue(Validator::isValid('08002', 'FR'));

$noPostCodeCountries = ['AE', 'AU', 'BA', 'CO', 'QA'];
foreach ($noPostCodeCountries as $country) {
Expand Down

0 comments on commit 11ef712

Please sign in to comment.