Thema: Delphi IBAN überprüfen

Einzelnen Beitrag anzeigen

Benutzerbild von HeikoAdams
HeikoAdams

Registriert seit: 12. Jul 2004
Ort: Oberfranken
661 Beiträge
 
FreePascal / Lazarus
 
#1

IBAN überprüfen

  Alt 23. Mär 2011, 09:47
Hallo,
mit dem folgenden Code kann man eine deutsche IBAN auf Korrektheit prüfen. Den Code für die Funktion Modulo97PruefZiffer habe ich von http://www.delphipraxis.net/1061658-post6.html übernommen. Der Algorithmus zum Prüfen der IBAN ist unter http://www.europebanks.info/ibanguide.htm#6 beschrieben.

Delphi-Quellcode:
function Modulo97PruefZiffer(const aIBAN:string):Integer;
const
   m36:string = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var
   nCounter, nPruef : Integer;
begin
   Result := 0;

   for nCounter := 1 to Length(aIBAN) do
   begin
      nPruef := Pos(aIBAN[nCounter], m36) ;

      if (nPruef = 0) then
         raise Exception.CreateFmt('Modulo97PruefZiffer(%s): invalid data', [aIBAN]);

      Dec(nPruef);

      if (nPruef > 9) then
      begin
         Result := Result * 10 + (nPruef div 10);
         nPruef := nPruef mod 10;
      end;

      Result := Result * 10 + nPruef;
      Result := Result mod 97;
   end;
end;

function CodiereLand(const aLand: string): string;
var
  sLetter: Char;
begin
  for sLetter in aLand do
    case sLetter of
      'A': Result := Result + '10';
      'B': Result := Result + '11';
      'C': Result := Result + '12';
      'D': Result := Result + '13';
      'E': Result := Result + '14';
      'F': Result := Result + '15';
      'G': Result := Result + '16';
      'H': Result := Result + '17';
      'I': Result := Result + '18';
      'J': Result := Result + '19';
      'K': Result := Result + '20';
      'L': Result := Result + '21';
      'M': Result := Result + '22';
      'N': Result := Result + '23';
      'O': Result := Result + '24';
      'P': Result := Result + '25';
      'Q': Result := Result + '26';
      'R': Result := Result + '27';
      'S': Result := Result + '28';
      'T': Result := Result + '29';
      'U': Result := Result + '30';
      'V': Result := Result + '31';
      'W': Result := Result + '32';
      'X': Result := Result + '33';
      'Y': Result := Result + '34';
      'Z': Result := Result + '35';
    else
      Result := Result + EmptyStr;
    end;
end;

function PruefeIBAN(const aIBAN: string): boolean;
var
  sBLZ: string;
  sKTO: string;
  sIBAN: string;
  sLand: string;
  sLand2: string;
  sControl: string;
begin
    sLand := Copy(aIBAN, 1, 2);

    if (sLand <> 'DE') then
    begin
      Result := true;
      Exit;
    end;

    sControl := Copy(aIBAN, 3, 2);
    sBLZ := Copy(aIBAN, 5, 8);
    sKTO := Copy(aIBAN, 13, 10);
    sLand2 := CodiereLand(sLand);
    sIBAN := sBLZ + sKTO + sLand2 + sControl;

    Result := (Modulo97PruefZiffer(sIBAN) = 1);
end;
Jeder kann ein Held werden und Leben retten!
Einfach beim NKR oder der DKMS als Stammzellenspender registrieren! Also: worauf wartest Du noch?

Geändert von HeikoAdams (23. Mär 2011 um 10:58 Uhr)
  Mit Zitat antworten Zitat