File tree 2 files changed +19
-8
lines changed
2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -22,13 +22,13 @@ class Validator
22
22
'DK ' => '(\d{2} ?){3}\d{2} ' ,
23
23
'EE ' => '\d{9} ' ,
24
24
'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}) ' ,
26
26
'FI ' => '\d{8} ' ,
27
27
'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}) ' ,
29
29
'HR ' => '\d{11} ' ,
30
30
'HU ' => '\d{8} ' ,
31
- 'IE ' => '[A-Z\d]{8}|[A-Z\d]{9} ' ,
31
+ 'IE ' => '( [A-Z\d]{8}|[A-Z\d]{9}) ' ,
32
32
'IT ' => '\d{11} ' ,
33
33
'LT ' => '(\d{9}|\d{12}) ' ,
34
34
'LU ' => '\d{8} ' ,
@@ -106,8 +106,7 @@ public function validateVatNumberFormat(string $vatNumber) : bool
106
106
return false ;
107
107
}
108
108
109
- $ matches = preg_match ('/^ ' . $ this ->patterns [$ country ] . '$/ ' , $ number ) > 0 ;
110
- return $ matches ;
109
+ return preg_match ('/^ ' . $ this ->patterns [$ country ] . '$/ ' , $ number ) > 0 ;
111
110
}
112
111
113
112
/**
Original file line number Diff line number Diff line change 9
9
/**
10
10
* Class ValidatorTest
11
11
* @package DvK\Tests\Vat
12
- *
13
- * Todo: Tests for validate method
14
12
*/
15
13
class ValidatorTest extends TestCase
16
14
{
@@ -92,7 +90,21 @@ public function testValidateVatNumberFormat()
92
90
'SE12345678901 ' ,
93
91
'SI1234567 ' ,
94
92
'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 ' ,
96
108
];
97
109
98
110
foreach ($ invalid as $ format ) {
You can’t perform that action at this time.
0 commit comments