Validate norweigan bankaccounts

Had big problems finding information on validating bank account numbers for Norway. Therefor I publish my php function here:

function validateNoBankAccount($account_number, $weight='5432765432') {
  if (strlen($account_number)!=11) {return false;}
  $digits = str_split($account_number);
  $control = str_split($weight);
  $total = 0;
  for ($i=0; $i<=9; $i++) {
    $total += $digits[$i]*$control[$i];
  }
  $checkdigit = 11-($total%11);
  return substr($account_number,-1)==$checkdigit;
}

Kommentarer

Skriv et svar

Din e-mailadresse vil ikke blive publiceret. Krævede felter er markeret med *