ואגב להלן הקוד הנוכחי שלי ב PHP.
אם יש כאן מה לתקן, אשמח..
<?php
var_dump(accountValidation(52, 177, 111111));
function accountValidation($bank, $branch, $account): bool
{
$bank = str_pad((string)($bank ?? 0), 2, '0', STR_PAD_LEFT);
$branch = str_pad((string)($branch ?? 0), 3, '0', STR_PAD_LEFT);
$account = (string)($account ?? 0);
if (strlen($branch) > 3 || strlen($bank) > 2) return false;
if ($bank == 10 || $bank == 13 || $bank == 34) {
$maxLen = 8;
if (strlen($account) > $maxLen) return false;
$account = str_pad($account, $maxLen, '0', STR_PAD_LEFT);
$counter = (int)(substr($account, 6, 2));
$r = $branch . $account;
for ($i = 0, $mul = 10; $i < 9; $i++ , $mul--)
$counter += (int)($r[$i]) * $mul;
$result = $counter % 100;
return $result == 90 || $result == 72 || $result == 70 || $result == 60 || $result == 20;
} else if ($bank == 12) {
$maxLen = 6;
if (strlen($account) > $maxLen) return false;
$account = str_pad($account, $maxLen, '0', STR_PAD_LEFT);
$counter = 0;
$r = $branch . $account;
for ($i = 0,$mul = 9;$i < 9; $i++ , $mul--)
$counter += (int)($r[$i]) * $mul;
$div = $counter % 11;
return $div == 0 || $div == 2 || $div == 4 || $div == 6;
} else if ($bank == 4) {
$maxLen = 6;
if (strlen($account) > $maxLen) return false;
$account = str_pad($account, $maxLen, '0', STR_PAD_LEFT);
$counter = 0;
$r = $branch . $account;
for ($i = 0,$mul = 9;$i < 9; $i++ , $mul--)
$counter += (int)($r[$i]) * $mul;
$div = $counter % 11;
return $div == 0 || $div == 2;
} else if ($bank == 11 || $bank == 17) {
$maxLen = 9;
if (strlen($account) > $maxLen) return false;
$account = str_pad($account, $maxLen, '0', STR_PAD_LEFT);
$counter = 0;
$r = $account;
for ($i = 0,$mul = 9;$i < 9; $i++ , $mul--)
$counter += (int)($r[$i]) * $mul;
$div = $counter % 11;
return$div == 0 ||$div == 2 ||$div == 4;
} else if ($bank == 20) {
$maxLen = 6;
if (strlen($account) > $maxLen) return false;
$account = str_pad($account, $maxLen, '0', STR_PAD_LEFT);
$counter = 0;
if ((int)$branch > 400) $branch = str_pad((string)((int)$branch - 400), 3, '0', STR_PAD_LEFT);
$r = $branch . $account;
for ($i = 0,$mul = 9;$i < 9; $i++ , $mul--)
$counter += (int)($r[$i]) * $mul;
$div = $counter % 11;
return $div == 0 ||$div == 2 ||$div == 4 ||$div == 6;
} else if ($bank == 31 || $bank == 52) {
$maxLen = 9;
if (strlen($account) > $maxLen) return false;
$account = str_pad($account, $maxLen, '0', STR_PAD_LEFT);
$counter = 0;
$r = $account;
for ($i = 0,$mul = 9;$i < 9;$i++ ,$mul--)
$counter += (int)($r[$i]) * $mul;
$div = $counter % 11;
if ($div == 0 ||$div == 6) return true;
$counter = 0;
$r = substr($account, 3);
for ($i = 0,$mul = 6;$i < 6;$i++ ,$mul--)
$counter += (int)($r[$i]) * $mul;
$div = $counter % 11;
return $div == 0 || $div == 6;
} else if ($bank == 9) {
$maxLen = 9;
if (strlen($account) > $maxLen) return false;
$account = str_pad($account, $maxLen, '0', STR_PAD_LEFT);
$counter = 0;
$r = $account;
for ($i = 0,$mul = 9;$i < 9;$i++ ,$mul--)
$counter += (int)($r[$i]) * $mul;
return ($counter % 10) == 0;
} else if ($bank == 22) {
$maxLen = 9;
if (strlen($account) > $maxLen) return false;
$account = str_pad($account, $maxLen, '0', STR_PAD_LEFT);
$counter = 0;
$r = $account;
$counter += (int)($r[0]) * 3;
$counter += (int)($r[1]) * 2;
for ($i = 2,$mul = 7;$i < 8;$i++ ,$mul--)
$counter += (int)($r[$i]) * $mul;
return (11 - ($counter % 11)) == $r[8];
} else if ($bank == 46) {
$maxLen = 6;
$account1 = $account;
if(strlen($account1) > $maxLen)
$account1 = substr($account, strlen($account) - $maxLen);
$account1 = str_pad($account1, $maxLen, '0', STR_PAD_LEFT);
$counter = 0;
$r = $branch . $account1;
for ($i = 0,$mul = 9;$i < 9;$i++ ,$mul--)
$counter += (int)($r[$i]) * $mul;
$div = $counter % 11;
$special = [ 192, 191, 183 ,181, 178, 166, 154, 539, 527, 516, 515, 507, 505, 503 ];
if ($div == 0 || ($div == 2 && in_array($branch, $special))) return true;
$maxLen = 9;
if (strlen($account) > $maxLen) return false;
$account2 = str_pad($account, $maxLen, '0', STR_PAD_LEFT);
$counter = 0;
$r = $account2;
for ($i = 0,$mul = 9;$i < 9;$i++ ,$mul--)
$counter += (int)($r[$i]) * $mul;
if(($counter % 11) == 0) return true;
$account3 = substr($account, 3);
$counter = 0;
$r = $account3;
for ($i = 0,$mul = 9;$i < 9;$i++ ,$mul--)
$counter += (int)($r[$i]) * $mul;
return ($counter % 11) == 0;
} else if ($bank == 14) {
$maxLen = 6;
$account1 = $account;
if(strlen($account1) > $maxLen)
$account1 = substr($account, strlen($account) - $maxLen);
$account1 = str_pad($account1, $maxLen, '0', STR_PAD_LEFT);
$counter = 0;
$r = $branch . $account1 ;
for ($i = 0,$mul = 9;$i < 9;$i++ ,$mul--)
$counter += (int)($r[$i]) * $mul;
$div = $counter % 11;
$specialA = [ 385, 384 , 365, 347 ];
$specialB = [ 361 ,362 ,363 ];
if($div == 0) return true;
if(in_array($branch, $specialA) && ($div == 0 ||$div == 2)) return true;
if(in_array($branch, $specialB) && ($div == 0 ||$div == 2 ||$div == 4)) return true;
$maxLen = 9;
if (strlen($account) > $maxLen) return false;
$account2 = str_pad($account, $maxLen, '0', STR_PAD_LEFT);
$counter = 0;
$r = $account2;
for ($i = 0,$mul = 9;$i < 9;$i++ ,$mul--)
$counter += (int)($r[$i]) * $mul;
if(($counter % 11) == 0) return true;
$account3 = substr($account, 3);
$counter = 0;
$r = $account3;
for ($i = 0,$mul = 9;$i < 9;$i++ ,$mul--)
$counter += (int)($r[$i]) * $mul;
return ($counter % 11) == 0;
}
return false;
}