Skip to content

Commit

Permalink
Merge pull request #14 from faustbrian/patch-1
Browse files Browse the repository at this point in the history
Support for 7-digit postal codes in Egypt
  • Loading branch information
BenMorel authored Sep 15, 2024
2 parents fd74d11 + 5d43212 commit 59236ee
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Formatter/EGFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
/**
* Validates and formats postcodes in Egypt.
*
* Postcodes consist of 5 digits, without separator.
* Postcodes consist of 5 or 7 digits, without separator.
*
* @see https://en.wikipedia.org/wiki/List_of_postal_codes
* @see https://en.wikipedia.org/wiki/List_of_postal_codes_in_Egypt
* @see https://www.upu.int/UPU/media/upu/PostalEntitiesFiles/addressingUnit/egyEn.pdf
*/
class EGFormatter implements CountryPostcodeFormatter
{
Expand All @@ -21,7 +22,7 @@ class EGFormatter implements CountryPostcodeFormatter
*/
public function format(string $postcode) : ?string
{
if (preg_match('/^[0-9]{5}$/', $postcode) !== 1) {
if (preg_match('/^\d{5}(\d{2})?$/', $postcode) !== 1) {
return null;
}

Expand Down

0 comments on commit 59236ee

Please sign in to comment.