From df15506844692d27cb62312aa922e29ccdf46687 Mon Sep 17 00:00:00 2001 From: Andreas Weswaldi <37552851+weswaldix@users.noreply.github.com> Date: Fri, 20 Sep 2024 00:35:19 +0200 Subject: [PATCH] Fix: Validate Austrian post codes to exclude invalid values starting 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). --- src/Formatter/ATFormatter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Formatter/ATFormatter.php b/src/Formatter/ATFormatter.php index d010f47..80c199a 100644 --- a/src/Formatter/ATFormatter.php +++ b/src/Formatter/ATFormatter.php @@ -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 @@ -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; }