Skip to content

Commit bd80f40

Browse files
committed
CompanyRegistrationNumber - add greece validator
1 parent b0fb921 commit bd80f40

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/CompanyRegistrationNumber.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,32 @@ private function isValid(
5151
$this->isValidNL($value) ||
5252
$this->isValidPT($value) ||
5353
$this->isValidLU($value) ||
54-
$this->isValidIE($value);
54+
$this->isValidIE($value) ||
55+
$this->isValidEL($value);
5556
}
5657

58+
private function isValidEL(
59+
string $value
60+
): bool {
61+
if(!\preg_match('/^\d{9}$/', $value)) {
62+
return false;
63+
}
64+
65+
if($value === '000000000') {
66+
return false;
67+
}
68+
69+
$sum = 0;
70+
71+
for($i = 0; $i < 8; $i++) {
72+
$sum += ((int) $value[$i]) << 8 - $i;
73+
}
74+
75+
$remainder = $sum % 11 % 10;
76+
77+
return $remainder === (int) $value[8];
78+
}
79+
5780
private function isValidIE(
5881
string $value
5982
): bool {

tests/CompanyRegistrationNumberTest.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ final class CompanyRegistrationNumberTest extends TestCase
5656
'1234567T', // IE
5757
'1234567FA',// IE
5858
'2036426OA',// IE
59+
'996861833', // EL
5960
];
6061

6162
foreach ($validValues as $validValue) {

0 commit comments

Comments
 (0)