From 1965dde96b828877cbcaf61c55b07c7143c4272d Mon Sep 17 00:00:00 2001 From: niels Date: Tue, 18 Feb 2025 15:48:23 +0100 Subject: [PATCH 1/2] Update validator and add additional number to test --- src/Vies/Validator/ValidatorLV.php | 6 +++--- tests/Vies/Validator/ValidatorLVTest.php | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Vies/Validator/ValidatorLV.php b/src/Vies/Validator/ValidatorLV.php index d8c5520..e702a92 100644 --- a/src/Vies/Validator/ValidatorLV.php +++ b/src/Vies/Validator/ValidatorLV.php @@ -19,7 +19,6 @@ * * Range: * C1 ... C11 Numeric from 0 to 9 - * C1 > 3 * * Rules: * C11 @@ -40,8 +39,9 @@ public function validate(string $vatNumber): bool return false; } - if ((int)$vatNumber[0] <= 3) { - return false; + // Differentiate between legal entities and natural bodies. For the latter, there is a simpler check + if (preg_match('/^[0-3]/', $vatNumber)) { + return preg_match('/^[0-3][0-9][0-1][0-9]/', $vatNumber) == 1; } $weights = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6]; diff --git a/tests/Vies/Validator/ValidatorLVTest.php b/tests/Vies/Validator/ValidatorLVTest.php index 2593770..e241b05 100644 --- a/tests/Vies/Validator/ValidatorLVTest.php +++ b/tests/Vies/Validator/ValidatorLVTest.php @@ -19,6 +19,7 @@ public function vatNumberProvider() { return [ ['40003009497', true], + ['10038010132', true], ['40013009497', false], ['40003009496', false], ['1234567890', false], From cbc67e67a2254c9c81ebe601ff229f0d709c9635 Mon Sep 17 00:00:00 2001 From: niels Date: Tue, 18 Feb 2025 15:52:55 +0100 Subject: [PATCH 2/2] Use \d instead of [0-9] --- src/Vies/Validator/ValidatorLV.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Vies/Validator/ValidatorLV.php b/src/Vies/Validator/ValidatorLV.php index e702a92..70d0cb5 100644 --- a/src/Vies/Validator/ValidatorLV.php +++ b/src/Vies/Validator/ValidatorLV.php @@ -41,7 +41,7 @@ public function validate(string $vatNumber): bool // Differentiate between legal entities and natural bodies. For the latter, there is a simpler check if (preg_match('/^[0-3]/', $vatNumber)) { - return preg_match('/^[0-3][0-9][0-1][0-9]/', $vatNumber) == 1; + return preg_match('/^[0-3]\d[0-1]\d/', $vatNumber) == 1; } $weights = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6];