Skip to content

Commit

Permalink
CompanyRegistrationNumber - add greece validator
Browse files Browse the repository at this point in the history
  • Loading branch information
Bleksak committed May 22, 2024
1 parent b0fb921 commit bd80f40
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/CompanyRegistrationNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,32 @@ private function isValid(
$this->isValidNL($value) ||
$this->isValidPT($value) ||
$this->isValidLU($value) ||
$this->isValidIE($value);
$this->isValidIE($value) ||
$this->isValidEL($value);
}

private function isValidEL(
string $value
): bool {
if(!\preg_match('/^\d{9}$/', $value)) {
return false;
}

if($value === '000000000') {
return false;
}

$sum = 0;

for($i = 0; $i < 8; $i++) {
$sum += ((int) $value[$i]) << 8 - $i;
}

$remainder = $sum % 11 % 10;

return $remainder === (int) $value[8];
}

private function isValidIE(
string $value
): bool {
Expand Down
1 change: 1 addition & 0 deletions tests/CompanyRegistrationNumberTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ final class CompanyRegistrationNumberTest extends TestCase
'1234567T', // IE
'1234567FA',// IE
'2036426OA',// IE
'996861833', // EL
];

foreach ($validValues as $validValue) {
Expand Down

0 comments on commit bd80f40

Please sign in to comment.