Forum > General

Bad Wiki example of IsValidIBAN(s)

(1/2) > >>

Alextp:
https://wiki.freepascal.org/International_Bank_Account_Number

This code fails on several OK numbers from this table:
https://en.wikipedia.org/wiki/International_Bank_Account_Number#Structure

e.g. on Brazil code / CostaRica code.

Also it contains call of DelSpace which must be replaced to StringReplace().

winni:
Hi

a) The example for the brasilian IBAN is wrong.
  Take the german issue of wikipedia where it is ok:
   https://de.wikipedia.org/wiki/Internationale_Bankkontonummer

b) It is international  standard to group the IBAN in blocks of 4 alphadecimals for better readability. Every child knows that the spaces exists only for readability.

Winni

Alextp:
It fails not only on Brazil code.

DelSpaces() call is not LCL usual call, it must be replaced.

Bart:

--- Quote from: Alextp on November 28, 2021, 08:19:35 pm ---DelSpaces() call is not LCL usual call, it must be replaced.

--- End quote ---


DelSPace is part of StrUtils unit that comes with fpc.
Not really a reason to replace it with StringReplace, which b.t.w. is also not part of LCL.

The code in the example feels a bit clumsy with the repeated copy()/delete() sequences.

Bart

trev:
If there's no objections, I will replace the existing code with:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Program iban; {$mode objFPC} {$H+} Uses StrUtils, SysUtils; // Calculate Modulo 97-10function StrMOD97(s: String): integer;const  modu = 97;var  sx: String;  isx, ic, p: Integer;begin   p := Length(s);   while (p > 9) do     begin       sx := Copy(s, 1, 9);       Delete(s, 1, 9);       isx := StrToInt(sx);       ic := isx mod modu;       s := IntToStr(ic) + s;       p := Length(s);     end;   isx := StrToInt(s);   if isx >= modu     then ic := isx mod modu   else ic := isx;  result := ic;end; // IBAN letter to number algorithmfunction ReplaceLetterWithNumber(ch: char):string;begin  result := IntToStr(ord(upCase(ch)) - ord('A') + 10);end;    // Check IBAN validityfunction IsValidIBAN( s: string ): boolean;var  a_char: char;  s1: string = '';  i: integer = 0;begin  // Delete any spaces  s := DelSpace(s);   // Move country code and checksum to end of string  s := s + copy(s, 1, 4);  delete(s, 1, 4);   // Convert any letters to numbers  for i := 1 to Length(s)  do    if((s[i]) in ['A'..'Z']) then      begin        a_char := s[i];        s1 := s1 + ReplaceLetterWithNumber(a_char);      end    else      s1 := s1 + s[i];   result := (StrMOD97(s1) = 1);end; begin  writeLn('GB82 WEST 1234 5698 7654 32: ', isValidIBAN('GB82WEST12345698765432'));  writeLn('GB82 TEST 1234 5698 7654 32: ', isValidIBAN('GB82TEST12345698765432'));  writeLn('CH93 0076 2011 6238 5295 7: ', isValidIBAN('CH93 0076 2011 6238 5295 7'));  writeLn('IL62 0108 0000 0009 9999 999: ', isValidIBAN('IL62 0108 0000 0009 9999 999'));  writeLn('GR16 0110 1250 0000 0001 2300 695: ', isValidIBAN('GR16 0110 1250 0000 0001 2300 695'));  writeLn('US12 3456 7890 0987 6543 210: ', isValidIBAN('US12 3456 7890 0987 6543 210'));  writeLn('LC14 BOSL 1234 5678 9012 3456 7890 1234: ', isValidIBAN('LC14 BOSL 1234 5678 9012 3456 7890 1234'));  writeLn('BR15 0000 0000 0000 1093 2840 814 P2: ', isValidIBAN('BR15 0000 0000 0000 1093 2840 814 P2'));end.

Navigation

[0] Message Index

[#] Next page

Go to full version