Skip to content

Commit 38dcd80

Browse files
merge #25
2 parents 97c9b67 + c3c8c1c commit 38dcd80

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/Validator.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class Validator
2222
'DK' => '(\d{2} ?){3}\d{2}',
2323
'EE' => '\d{9}',
2424
'EL' => '\d{9}',
25-
'ES' => '[A-Z]\d{7}[A-Z]|\d{8}[A-Z]|[A-Z]\d{8}',
25+
'ES' => '([A-Z]\d{7}[A-Z]|\d{8}[A-Z]|[A-Z]\d{8})',
2626
'FI' => '\d{8}',
2727
'FR' => '[A-Z\d]{2}\d{9}',
28-
'GB' => '\d{9}|\d{12}|(GD|HA)\d{3}',
28+
'GB' => '(\d{9}|\d{12}|(GD|HA)\d{3})',
2929
'HR' => '\d{11}',
3030
'HU' => '\d{8}',
31-
'IE' => '[A-Z\d]{8}|[A-Z\d]{9}',
31+
'IE' => '([A-Z\d]{8}|[A-Z\d]{9})',
3232
'IT' => '\d{11}',
3333
'LT' => '(\d{9}|\d{12})',
3434
'LU' => '\d{8}',
@@ -106,8 +106,7 @@ public function validateVatNumberFormat(string $vatNumber) : bool
106106
return false;
107107
}
108108

109-
$matches = preg_match('/^' . $this->patterns[$country] . '$/', $number) > 0;
110-
return $matches;
109+
return preg_match('/^' . $this->patterns[$country] . '$/', $number) > 0;
111110
}
112111

113112
/**

tests/ValidatorTest.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
/**
1010
* Class ValidatorTest
1111
* @package DvK\Tests\Vat
12-
*
13-
* Todo: Tests for validate method
1412
*/
1513
class ValidatorTest extends TestCase
1614
{
@@ -92,7 +90,21 @@ public function testValidateVatNumberFormat()
9290
'SE12345678901',
9391
'SI1234567',
9492
'SK123456789',
95-
'fooGB999999973', // valid VAT number but with string prefix
93+
94+
// valid number but with prefix
95+
'invalid_prefix_GB999999973',
96+
'invalid_prefix_IE1234567X',
97+
'invalid_prefix_ESB1234567C',
98+
'invalid_prefix_BE0123456789',
99+
'invalid_prefix_MT12345678',
100+
'invalid_prefix_LT123456789',
101+
102+
// valid number but with suffix
103+
'IE1234567X_invalid_suffix',
104+
'ESB1234567C_invalid_suffix',
105+
'BE0123456789_invalid_suffix',
106+
'MT12345678_invalid_suffix',
107+
'LT123456789_invalid_suffix',
96108
];
97109

98110
foreach ($invalid as $format) {

0 commit comments

Comments
 (0)