From a5b7d60147d7ee6423ed75c99828aadd987a1e73 Mon Sep 17 00:00:00 2001 From: Pierre Queyroi Date: Mon, 30 Nov 2026 04:42:56 +0100 Subject: [PATCH] Restrict GL postcodes to 39NN --- src/Formatter/GLFormatter.php | 5 +++-- tests/Formatter/GLFormatterTest.php | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Formatter/GLFormatter.php b/src/Formatter/GLFormatter.php index 17a6783..e1f733f 100644 --- a/src/Formatter/GLFormatter.php +++ b/src/Formatter/GLFormatter.php @@ -12,16 +12,17 @@ /** * Validates and formats postcodes in Greenland. * - * Postcodes consist of 4 digits, without separator. + * Postcode format is 39NN, where N stands for a digit. * * @see https://en.wikipedia.org/wiki/List_of_postal_codes + * @see https://en.wikipedia.org/wiki/Postal_codes_in_Greenland */ final class GLFormatter implements CountryPostcodeFormatter { #[Override] public function format(string $postcode): ?string { - if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) { + if (preg_match('/^39[0-9]{2}$/', $postcode) !== 1) { return null; } diff --git a/tests/Formatter/GLFormatterTest.php b/tests/Formatter/GLFormatterTest.php index 5225b98..5724d55 100644 --- a/tests/Formatter/GLFormatterTest.php +++ b/tests/Formatter/GLFormatterTest.php @@ -21,7 +21,11 @@ public static function providerFormat(): array ['1', null], ['12', null], ['123', null], - ['1234', '1234'], + ['1234', null], + ['3899', null], + ['3900', '3900'], + ['3999', '3999'], + ['4000', null], ['12345', null], ['A', null],