Sign in Join
Wiki copytemporary

International Bank Account Number/fi: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: International Bank Account Number/fi

OldNewLine
1+Kansainvälinen pankkitilinumero ( IBAN = International Bank Account Number ) on kansainvälinen standardi pankkien tilinumeroista. Se on määritelty ISO 13616 standardissa. IBAN sisältää maksimissaan 34 merkkiä, joka sisältää maa koodin, kaksi tarkistusnumeroa ja yksilöivän pankin tilinumeron.
2+
3+Maakoodissa ilmoitetaan ISO 3166-1 alpha-2 standardin mukaisesti. Tarkistusnumero lasketaan [[ISO 7064]] (MOD97-10) standardin mukaisesti.
4+
5+## Funktio IsValidIban
6+
7+Funktio IsValidIban tarkistaa onko kansainvälinen pankkitilinumero sääntöjen mukainen. Funktio StrMOD97 löytyy täältä [[ISO 7064|ISO_7064#Function StrMOD97]]
8+
9+``` pascal
10+Program iban;
11+
12+{$mode objFPC} {$H+}
13+
14+Uses
15+ StrUtils, SysUtils;
16+
17+// Calculate Modulo 97-10
18+function StrMOD97(s: String): integer;
19+const
20+ modu = 97;
21+var
22+ sx: String;
23+ isx, ic, p: Integer;
24+begin
25+ p := Length(s);
26+ while (p > 9) do
27+ begin
28+ sx := Copy(s, 1, 9);
29+ Delete(s, 1, 9);
30+ isx := StrToInt(sx);
31+ ic := isx mod modu;
32+ s := IntToStr(ic) + s;
33+ p := Length(s);
34+ end;
35+ isx := StrToInt(s);
36+ if isx >= modu
37+ then ic := isx mod modu
38+ else ic := isx;
39+ result := ic;
40+end;
41+
42+function ProcessChar(ch: char):string;
43+begin
44+ if (ch in ['0'..'9']) then
45+ Result := ch
46+ else
47+ // IBAN letter to number algorithm
48+ if (ch in ['A'..'Z', 'a'..'z']) then
49+ result := IntToStr(ord(upCase(ch)) - ord('A') + 10)
50+ else
51+ result := '';
52+end;
53+
54+// Check IBAN validity
55+function IsValidIBAN(s: string): boolean;
56+var
57+ s1: string = '';
58+ ch: String;
59+ i: Integer;
60+begin
61+ Result := false;
62+
63+ // Delete any spaces
64+ s := DelSpace(s);
65+
66+ // Obvious tests
67+ if Length(s) < 4 then
68+ exit;
69+ if not ((s[1] in ['A'..'Z']) and (s[2] in ['A'..'Z'])) then
70+ exit;
71+ if not ((s[3] in ['0'..'9']) and (s[4] in ['0'..'9'])) then
72+ exit;
73+
74+ // Process number block first
75+ for i := 5 to Length(s) do
76+ begin
77+ ch := ProcessChar(s[i]); // Convert letters to numbers, keep numbers
78+ if ch = '' then
79+ exit;
80+ s1 := s1 + ch;
81+ end;
82+ // Move country code and check sum to the end of the test string
83+ for i := 1 to 4 do
84+ s1 := s1 + ProcessChar(s[i]);
85+
86+ result := (StrMOD97(s1) = 1);
87+end;
88+
89+type
90+ TTestRec = record
91+ TestIBAN: String;
92+ Expected: Boolean;
93+ end;
94+
95+const
96+ // Expected results validated by https://www.ibancalculator.com/iban_validieren.html
97+ Tests: array[0..10] of TTestRec = (
98+ (TestIBAN:'GB82 WEST 1234 5698 7654 32'; Expected: true),
99+ (TestIBAN:'GB82 TEST 1234 5698 7654 32'; Expected: false),
100+ (TestIBAN:'GB82 WEST12345698765432'; Expected: true),
101+ (TestIBAN:'GB 82WEST12345698765432'; Expected: true),
102+ (TestIBAN:'GB82 WEST123 456 987 654 32'; Expected: true),
103+ (TestIBAN:'CH93 0076 2011 6238 5295 7'; Expected: true),
104+ (TestIBAN:'IL62 0108 0000 0009 9999 999'; Expected: true),
105+ (TestIBAN:'GR16 0110 1250 0000 0001 2300 695'; Expected: true),
106+ (TestIBAN:'US12 3456 7890 0987 6543 210'; Expected: false),
107+ (TestIBAN:'LC14 BOSL 1234 5678 9012 3456 7890 1234'; Expected: true),
108+ (TestIBAN:'BR15 0000 0000 0000 1093 2840 814 P2'; Expected: true )
109+ );
110+ W = 40;
111+var
112+ i: Integer;
113+ s: String;
114+ ok: Boolean;
115+begin
116+ for i := 0 to High(Tests) do
117+ begin
118+ s := Tests[i].TestIBAN;
119+ ok := IsValidIBAN(s);
120+ if ok = Tests[i].Expected then
121+ begin
122+ if ok then
123+ WriteLn(s:W, ': Correct IBAN correctly detected')
124+ else
125+ WriteLn(s:W, ': Incorrect IBAN correctly detected.');
126+ end else
127+ if Tests[i].Expected then
128+ WriteLn(s:W, ': ERROR (Correct IBAN not detected)')
129+ else
130+ WriteLn(s:W, ': ERROR (Incorrect IBAN not detected)');
131+ end;
132+
133+ ReadLn;
134+end.
135+```
136+
137+---
138+*From the Free Pascal wiki, page "International Bank Account Number/fi", as it stood on 2021-11-30 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history