Skip to content

Commit

Permalink
feat: postcode validation for HR (#12)
Browse files Browse the repository at this point in the history
feat: postcode validation for HR
  • Loading branch information
turboatcrazyfactory authored Jan 22, 2020
2 parents a7f2002 + 9004d57 commit 169326a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ZipCode/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Validator
'FR' => ['AD111','11111'],
'GB' => ['AA11 1AA','A1A 1AA','AA1 1AA','AA1A 1AA','A11 1AA','A1 1AA'],
'GR' => ['11111'],
'HR' => ['11111'],
'HU' => ['1111'],
// 'IE' See above
'IT' => ['11111'],
Expand Down Expand Up @@ -66,6 +67,7 @@ class Validator
'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}',
'HU' => '\\d{4}',
// 'IE' => '[-1-9]{1}', See above
'IT' => '\\d{5}',
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/ZipCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public function testIsValid()
$this->assertFalse(Validator::isValid('A', 'DE'), 'DE: A');
$this->assertFalse(Validator::isValid('01234', 'LU'), 'LU');
$this->assertFalse(Validator::isValid('01234', 'RO'), 'RO');
$this->assertFalse(Validator::isValid('20207 MLINI', 'HR'), 'HR');
$this->assertTrue(Validator::isValid('123456', 'RO'), 'RO');
$this->assertTrue(Validator::isValid('01234', 'FR'), 'FR');
$this->assertTrue(Validator::isValid('M6 6SD', 'GB'), 'GB: M6 6SD');
$this->assertTrue(Validator::isValid('11111', 'HR'), 'HR: 11111');

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

0 comments on commit 169326a

Please sign in to comment.