Skip to content

Commit

Permalink
Fix: Validate Austrian post codes to exclude invalid values starting …
Browse files Browse the repository at this point in the history
…with 0 (#15)

Previously, postal codes such as '0000' or '0999' were considered valid, but in reality, Austrian postal codes always start with digits from 1 to 9. This update corrects the validation to ensure compliance with the Austrian postal code system (see: https://en.wikipedia.org/wiki/Postal_codes_in_Austria#System).
  • Loading branch information
weswaldix authored Sep 19, 2024
1 parent ef8ab8f commit df15506
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Formatter/ATFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Validates and formats postcodes in Austria.
*
* Postcodes consist of 4 digits, without separator.
* Postcodes consist of 4 digits, without separator. The first digit must be 1-9.
*
* @see https://en.wikipedia.org/wiki/List_of_postal_codes
* @see https://en.wikipedia.org/wiki/Postal_codes_in_Austria
Expand All @@ -21,7 +21,7 @@ class ATFormatter implements CountryPostcodeFormatter
*/
public function format(string $postcode) : ?string
{
if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) {
if (preg_match('/^[1-9][0-9]{3}$/', $postcode) !== 1) {
return null;
}

Expand Down

0 comments on commit df15506

Please sign in to comment.