IBAN: Difference between revisions

Content added Content deleted
(→‎{{header|Picat}}: Added subsection. added {{out}})
m (syntax highlighting fixup automation)
Line 24: Line 24:
{{trans|Python}}
{{trans|Python}}


<lang 11l>F mod97(numberstring)
<syntaxhighlight lang="11l">F mod97(numberstring)
V segstart = 0
V segstart = 0
V step = 9
V step = 9
Line 62: Line 62:
L(account) [‘GB82 WEST 1234 5698 7654 32’,
L(account) [‘GB82 WEST 1234 5698 7654 32’,
‘GB82 TEST 1234 5698 7654 32’]
‘GB82 TEST 1234 5698 7654 32’]
print(‘#. validation is: #.’.format(account, valid_iban(account)))</lang>
print(‘#. validation is: #.’.format(account, valid_iban(account)))</syntaxhighlight>


{{out}}
{{out}}
Line 71: Line 71:


=={{header|Ada}}==
=={{header|Ada}}==
<lang Ada>package Iban_Code is
<syntaxhighlight lang="ada">package Iban_Code is
function Is_Legal(Iban : String) return Boolean;
function Is_Legal(Iban : String) return Boolean;
end Iban_Code;</lang><lang Ada>with Ada.Characters.Handling; use Ada.Characters.Handling;
end Iban_Code;</syntaxhighlight><syntaxhighlight lang="ada">with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Containers.Hashed_Maps;
with Ada.Containers.Hashed_Maps;
with Ada.Strings.Hash;
with Ada.Strings.Hash;
Line 160: Line 160:
Nations.insert("TR", 26); Nations.insert("AE", 23);
Nations.insert("TR", 26); Nations.insert("AE", 23);
Nations.insert("GB", 22); Nations.insert("VG", 24);
Nations.insert("GB", 22); Nations.insert("VG", 24);
end Iban_Code;</lang>Testing:
end Iban_Code;</syntaxhighlight>Testing:
<lang Ada>with Ada.Text_Io; use Ada.Text_Io;
<syntaxhighlight lang="ada">with Ada.Text_Io; use Ada.Text_Io;
with Iban_Code;
with Iban_Code;


Line 181: Line 181:
Check("GB82 TEST 1234 5698 7654 32");
Check("GB82 TEST 1234 5698 7654 32");
Check("GB82 WEST 1243 5698 7654 32");
Check("GB82 WEST 1243 5698 7654 32");
end Check_Iban;</lang>{{out}}
end Check_Iban;</syntaxhighlight>{{out}}
GB82 WEST 1234 5698 7654 32 is valid.
GB82 WEST 1234 5698 7654 32 is valid.
GB82WEST12345698765432 is valid.
GB82WEST12345698765432 is valid.
Line 190: Line 190:
=={{header|AppleScript}}==
=={{header|AppleScript}}==


<lang applescript>on countryCodes()
<syntaxhighlight lang="applescript">on countryCodes()
-- A list of 34 lists. The nth list (1-indexed) contains country codes for countries having n-character IBANS.
-- A list of 34 lists. The nth list (1-indexed) contains country codes for countries having n-character IBANS.
return {{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {"NO"}, {"BE"}, ¬
return {{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {"NO"}, {"BE"}, ¬
Line 251: Line 251:
set output to output as text
set output to output as text
set AppleScript's text item delimiters to astid
set AppleScript's text item delimiters to astid
return output</lang>
return output</syntaxhighlight>


{{output}}
{{output}}
<lang applescript>"GB82 WEST 1234 5698 7654 32: valid
<syntaxhighlight lang="applescript">"GB82 WEST 1234 5698 7654 32: valid
gb82 west 1234 5698 7654 32: valid
gb82 west 1234 5698 7654 32: valid
GB82 TEST 1234 5698 7654 32: invalid
GB82 TEST 1234 5698 7654 32: invalid
SA03 8000 0000 6080 1016 7519: valid
SA03 8000 0000 6080 1016 7519: valid
ZZ12 3456 7890 1234 5678 12: invalid
ZZ12 3456 7890 1234 5678 12: invalid
IL62 0108 0000 0009 9999 999: valid"</lang>
IL62 0108 0000 0009 9999 999: valid"</syntaxhighlight>


=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>ibanSize: #[
<syntaxhighlight lang="rebol">ibanSize: #[
AL: 28, AD: 24, AT: 20, AZ: 28, BE: 16
AL: 28, AD: 24, AT: 20, AZ: 28, BE: 16
BH: 22, BA: 20, BR: 29, BG: 22, CR: 21, HR: 21, CY: 28
BH: 22, BA: 20, BR: 29, BG: 22, CR: 21, HR: 21, CY: 28
Line 293: Line 293:
loop ["GB82 WEST 1234 5698 7654 32"
loop ["GB82 WEST 1234 5698 7654 32"
"GB82 TEST 1234 5698 7654 32"] 'ib
"GB82 TEST 1234 5698 7654 32"] 'ib
-> print [ib "=> valid?" valid? ib]</lang>
-> print [ib "=> valid?" valid? ib]</syntaxhighlight>


{{out}}
{{out}}
Line 302: Line 302:
=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
{{works with|AutoHotkey 1.1}}
{{works with|AutoHotkey 1.1}}
<lang AutoHotkey>IBANs := ["GB82 WEST 1234 5698 7654 32"
<syntaxhighlight lang="autohotkey">IBANs := ["GB82 WEST 1234 5698 7654 32"
, "gb82 WEST 1234 5698 7654 32"
, "gb82 WEST 1234 5698 7654 32"
, "GB82WEST12345698765432"
, "GB82WEST12345698765432"
Line 344: Line 344:
}
}
return rem
return rem
}</lang>{{Out}}
}</syntaxhighlight>{{Out}}
GB82 WEST 1234 5698 7654 32 is valid.
GB82 WEST 1234 5698 7654 32 is valid.
gb82 WEST 1234 5698 7654 32 is valid.
gb82 WEST 1234 5698 7654 32 is valid.
Line 357: Line 357:
This requires a gawk with extensions and GNU MP+MPFR support - it's usually the case. Some country codes are missing, the output is itself parsable.
This requires a gawk with extensions and GNU MP+MPFR support - it's usually the case. Some country codes are missing, the output is itself parsable.


<lang awk>
<syntaxhighlight lang="awk">
@load "ordchr"
@load "ordchr"


Line 407: Line 407:
ibancsum % 97 == 1 ? valid() : invalid()
ibancsum % 97 == 1 ? valid() : invalid()
}</lang>
}</syntaxhighlight>
Creating a test file and launching the script:
Creating a test file and launching the script:
<lang>
<syntaxhighlight lang="text">
cat > test.iban
cat > test.iban
FR33 ^__^ 0BAD
FR33 ^__^ 0BAD
Line 419: Line 419:
^D
^D
gawk -Mf iban.gawk test.iban
gawk -Mf iban.gawk test.iban
</syntaxhighlight>
</lang>


Output:
Output:


<lang>
<syntaxhighlight lang="text">
INVALID FR33 ^__^ 0BAD
INVALID FR33 ^__^ 0BAD
INVALID AA11 1234 6543 1212
INVALID AA11 1234 6543 1212
Line 430: Line 430:
VALID__ GB82 WEST 1234 5698 7654 32
VALID__ GB82 WEST 1234 5698 7654 32
INVALID GB82 TEST 1234 5698 7654 32
INVALID GB82 TEST 1234 5698 7654 32
</syntaxhighlight>
</lang>


=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> REM Used the following as official standard:
<syntaxhighlight lang="bbcbasic"> REM Used the following as official standard:
REM http://www.cnb.cz/cs/platebni_styk/iban/download/EBS204.pdf
REM http://www.cnb.cz/cs/platebni_styk/iban/download/EBS204.pdf


Line 526: Line 526:
num$=MID$(num$,8)
num$=MID$(num$,8)
ENDWHILE
ENDWHILE
=VALmod$</lang>{{out}}
=VALmod$</syntaxhighlight>{{out}}
valid IBAN: GB82 WEST 1234 5698 7654 32
valid IBAN: GB82 WEST 1234 5698 7654 32
valid IBAN: GB82WEST12345698765432
valid IBAN: GB82WEST12345698765432
Line 542: Line 542:
=={{header|Befunge}}==
=={{header|Befunge}}==


<lang befunge>>>" :NABI">:#,_>:~:"`"`48**-:55+-#v_$0::6g0>>8g-!\7g18g-!*!v>v>>
<syntaxhighlight lang="befunge">>>" :NABI">:#,_>:~:"`"`48**-:55+-#v_$0::6g0>>8g-!\7g18g-!*!v>v>>
<<_#v:#78#`8#+<^+!!*-*84\-9:g8:p8\<oo>1#$-#<0$>>>#v_"dilav" ^#<<
<<_#v:#78#`8#+<^+!!*-*84\-9:g8:p8\<oo>1#$-#<0$>>>#v_"dilav" ^#<<
>>^ >*-:20p9`9*1+55+**20g+"a"%10g1+00g%:4-!|^g6::_v#-*88:+1_vv>>
>>^ >*-:20p9`9*1+55+**20g+"a"%10g1+00g%:4-!|^g6::_v#-*88:+1_vv>>
Line 549: Line 549:
"-(&(/$$*$(*.-*.('$)*%0-&**.$'(.'/.+,''&&*.)**&,-.&.(*(*-!(%01-)
"-(&(/$$*$(*.-*.('$)*%0-&**.$'(.'/.+,''&&*.)**&,-.&.(*(*-!(%01-)
BFBBBBFFTNRRGGCCGCGGSSKSKSSDDHDHCPLPTLLLLPPAAVEIIAAAIEMMMNGMMMMI
BFBBBBFFTNRRGGCCGCGGSSKSKSSDDHDHCPLPTLLLLPPAAVEIIAAAIEMMMNGMMMMI
ERGAHRIONLSOTRZYBRLIKIWMZAEOKREUHSBTRIVTUKLEDGESTLTZESEDCOEKUTRL</lang>
ERGAHRIONLSOTRZYBRLIKIWMZAEOKREUHSBTRIVTUKLEDGESTLTZESEDCOEKUTRL</syntaxhighlight>


{{out}}
{{out}}
Line 560: Line 560:


=={{header|Bracmat}}==
=={{header|Bracmat}}==
<lang bracmat>( ( IBAN-check
<syntaxhighlight lang="bracmat">( ( IBAN-check
= table country cd len N c
= table country cd len N c
. (AL.28) (AD.24) (AT.20) (AZ.28) (BE.16) (BH.22) (BA.20) (BR.29)
. (AL.28) (AD.24) (AT.20) (AZ.28) (BE.16) (BH.22) (BA.20) (BR.29)
Line 610: Line 610:
& IBAN-check$"GB82 WEST 1243 5698 7654 32"
& IBAN-check$"GB82 WEST 1243 5698 7654 32"
& IBAN-check$"GB82 west 1243 5698 7654 32"
& IBAN-check$"GB82 west 1243 5698 7654 32"
);</lang>{{out}}
);</syntaxhighlight>{{out}}
wrong length
wrong length
invalid country code: 'GX'
invalid country code: 'GX'
Line 621: Line 621:


=={{header|C}}==
=={{header|C}}==
<lang C>#include <alloca.h>
<syntaxhighlight lang="c">#include <alloca.h>
#include <ctype.h>
#include <ctype.h>
#include <stdio.h>
#include <stdio.h>
Line 717: Line 717:


return 0;
return 0;
}</lang>{{out}}
}</syntaxhighlight>{{out}}
iban 'GB82 WEST 1234 5698 7654 32' GB82TEST12345698765432
iban 'GB82 WEST 1234 5698 7654 32' GB82TEST12345698765432
GB82WEST12345698765432 is valid.
GB82WEST12345698765432 is valid.
Line 723: Line 723:


=={{header|C sharp}}==
=={{header|C sharp}}==
<lang csharp> public class IbanValidator : IValidateTypes
<syntaxhighlight lang="csharp"> public class IbanValidator : IValidateTypes
{
{
public ValidationResult Validate(string value)
public ValidationResult Validate(string value)
Line 841: Line 841:
{"VG", 24}
{"VG", 24}
};
};
}</lang>Demonstrating:
}</syntaxhighlight>Demonstrating:
<lang csharp> public class When_the_IbanValidator_is_told_to_Validate
<syntaxhighlight lang="csharp"> public class When_the_IbanValidator_is_told_to_Validate
{
{
[Fact]
[Fact]
Line 941: Line 941:
Assert.Equal(ValidationResult.IsValid, result);
Assert.Equal(ValidationResult.IsValid, result);
}
}
}</lang>
}</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <string>
<syntaxhighlight lang="cpp">#include <string>
#include <iostream>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string.hpp>
Line 1,018: Line 1,018:
SayValidity("GB82TEST12345698765432");
SayValidity("GB82TEST12345698765432");
return 0;
return 0;
}</lang>{{out}}
}</syntaxhighlight>{{out}}
GB82 WEST 1234 5698 7654 32 is valid!
GB82 WEST 1234 5698 7654 32 is valid!
GB82TEST12345698765432 is not valid!
GB82TEST12345698765432 is not valid!
Line 1,024: Line 1,024:
=={{header|Caché ObjectScript}}==
=={{header|Caché ObjectScript}}==


<lang cos>Class Utils.Validate [ Abstract ]
<syntaxhighlight lang="cos">Class Utils.Validate [ Abstract ]
{
{


Line 1,121: Line 1,121:
}
}


}</lang>{{out|Examples}}
}</syntaxhighlight>{{out|Examples}}
<pre>USER>For { Read iban Quit:iban="" Write " => ", ##class(Utils.Validate).VerifyIBAN(iban), ! }
<pre>USER>For { Read iban Quit:iban="" Write " => ", ##class(Utils.Validate).VerifyIBAN(iban), ! }
GB82 WEST 1234 5698 7654 32 => 1
GB82 WEST 1234 5698 7654 32 => 1
Line 1,134: Line 1,134:


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang Clojure>(def explen
<syntaxhighlight lang="clojure">(def explen
{"AL" 28 "AD" 24 "AT" 20 "AZ" 28 "BE" 16 "BH" 22 "BA" 20 "BR" 29
{"AL" 28 "AD" 24 "AT" 20 "AZ" 28 "BE" 16 "BH" 22 "BA" 20 "BR" 29
"BG" 22 "CR" 21 "HR" 21 "CY" 28 "CZ" 24 "DK" 18 "DO" 28 "EE" 20
"BG" 22 "CR" 21 "HR" 21 "CY" 28 "CZ" 24 "DK" 18 "DO" 28 "EE" 20
Line 1,157: Line 1,157:


(prn (valid-iban? "GB82 WEST 1234 5698 7654 32") ; true
(prn (valid-iban? "GB82 WEST 1234 5698 7654 32") ; true
(valid-iban? "GB82 TEST 1234 5698 7654 32")) ; false</lang>
(valid-iban? "GB82 TEST 1234 5698 7654 32")) ; false</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
{{works with|OpenCOBOL}}
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. iban-main.
PROGRAM-ID. iban-main.


Line 1,321: Line 1,321:
END PROGRAM create-iban-number.
END PROGRAM create-iban-number.


END PROGRAM validate-iban.</lang>{{out}}
END PROGRAM validate-iban.</syntaxhighlight>{{out}}
<pre>
<pre>
GB82 WEST 1234 5698 7654 32 is valid.
GB82 WEST 1234 5698 7654 32 is valid.
Line 1,328: Line 1,328:


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
<lang lisp>
<syntaxhighlight lang="lisp">
;;
;;
;; List of the IBAN code lengths per country.
;; List of the IBAN code lengths per country.
Line 1,390: Line 1,390:
(= 1 (mod (IBAN-to-integer X) 97)))))
(= 1 (mod (IBAN-to-integer X) 97)))))
(validp (remove #\Space iban))))
(validp (remove #\Space iban))))
</syntaxhighlight>
</lang>
'''Output:'''
'''Output:'''
<pre>
<pre>
Line 1,403: Line 1,403:
=={{header|D}}==
=={{header|D}}==
{{trans|Python}}
{{trans|Python}}
<lang d>import std.stdio, std.string, std.regex, std.conv, std.bigint,
<syntaxhighlight lang="d">import std.stdio, std.string, std.regex, std.conv, std.bigint,
std.algorithm, std.ascii;
std.algorithm, std.ascii;


Line 1,439: Line 1,439:
"GB82 TEST 1234 5698 7654 32"])
"GB82 TEST 1234 5698 7654 32"])
writefln("%s validation is: %s", account, account.validIBAN);
writefln("%s validation is: %s", account, account.validIBAN);
}</lang>{{out}}
}</syntaxhighlight>{{out}}
<pre>GB82 WEST 1234 5698 7654 32 validation is: true
<pre>GB82 WEST 1234 5698 7654 32 validation is: true
GB82 TEST 1234 5698 7654 32 validation is: false</pre>
GB82 TEST 1234 5698 7654 32 validation is: false</pre>


=={{header|DBL}}==
=={{header|DBL}}==
<syntaxhighlight lang="dbl">;
<lang DBL>;
; Validate IBAN for DBL version 4 by Dario B.
; Validate IBAN for DBL version 4 by Dario B.
;
;
Line 1,599: Line 1,599:
ELSE ISVALID=
ELSE ISVALID=
XRETURN
XRETURN
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>GB82 WEST 1234 5698 7654 32 is valid
<pre>GB82 WEST 1234 5698 7654 32 is valid
Line 1,613: Line 1,613:
=={{header|Elixir}}==
=={{header|Elixir}}==
{{trans|Ruby}}
{{trans|Ruby}}
<lang elixir>defmodule IBAN do
<syntaxhighlight lang="elixir">defmodule IBAN do
@len %{ AL: 28, AD: 24, AT: 20, AZ: 28, BE: 16, BH: 22, BA: 20, BR: 29,
@len %{ AL: 28, AD: 24, AT: 20, AZ: 28, BE: 16, BH: 22, BA: 20, BR: 29,
BG: 22, CR: 21, HR: 21, CY: 28, CZ: 24, DK: 18, DO: 28, EE: 20,
BG: 22, CR: 21, HR: 21, CY: 28, CZ: 24, DK: 18, DO: 28, EE: 20,
Line 1,648: Line 1,648:
"GB82 TEST 1234 5698 7654 32",
"GB82 TEST 1234 5698 7654 32",
"ZZ12 3456 7890 1234 5678 12" ]
"ZZ12 3456 7890 1234 5678 12" ]
|> Enum.each(fn iban -> IO.puts "#{IBAN.valid?(iban)}\t#{iban}" end)</lang>
|> Enum.each(fn iban -> IO.puts "#{IBAN.valid?(iban)}\t#{iban}" end)</syntaxhighlight>


{{out}}
{{out}}
Line 1,661: Line 1,661:


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>open System
<syntaxhighlight lang="fsharp">open System
open System.Text.RegularExpressions
open System.Text.RegularExpressions


Line 1,712: Line 1,712:
|> function | Some(_) -> "a valid IBAN" | None -> "an invalid IBAN"
|> function | Some(_) -> "a valid IBAN" | None -> "an invalid IBAN"
|> printfn "%s is %s" iban
|> printfn "%s is %s" iban
0</lang>{{out}}
0</syntaxhighlight>{{out}}
>Rosetta.exe "GB82 WEST 1234 5698 7654 32"
>Rosetta.exe "GB82 WEST 1234 5698 7654 32"
GB82 WEST 1234 5698 7654 32 is a valid IBAN
GB82 WEST 1234 5698 7654 32 is a valid IBAN
Line 1,720: Line 1,720:


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: assocs combinators.short-circuit formatting kernel math
<syntaxhighlight lang="factor">USING: assocs combinators.short-circuit formatting kernel math
math.parser regexp sequences sets qw unicode ;
math.parser regexp sequences sets qw unicode ;
IN: rosetta-code.iban
IN: rosetta-code.iban
Line 1,769: Line 1,769:
] bi@ ;
] bi@ ;


MAIN: iban-demo</lang>
MAIN: iban-demo</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,778: Line 1,778:
=={{header|Forth}}==
=={{header|Forth}}==
{{Works with|4tH|3.62.3}}
{{Works with|4tH|3.62.3}}
<lang>include lib/ulcase.4th \ for S>UPPER
<syntaxhighlight lang="text">include lib/ulcase.4th \ for S>UPPER
include lib/triple.4th \ for UT/MOD
include lib/triple.4th \ for UT/MOD
include lib/cstring.4th \ for C/STRING
include lib/cstring.4th \ for C/STRING
Line 1,815: Line 1,815:
;
;


checkiban</lang>
checkiban</syntaxhighlight>
{{Out}}
{{Out}}
<pre>linux:~> pp4th -x chkiban.4th
<pre>linux:~> pp4th -x chkiban.4th
Line 1,825: Line 1,825:


=={{header|Fortran}}==
=={{header|Fortran}}==
<lang fortran>
<syntaxhighlight lang="fortran">
program ibancheck
program ibancheck


Line 1,950: Line 1,950:


end program ibancheck
end program ibancheck
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,969: Line 1,969:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64


' List updated to release 72, 25 November 2016, of IBAN Registry (75 countries)
' List updated to release 72, 25 November 2016, of IBAN Registry (75 countries)
Line 2,040: Line 2,040:
Print
Print
Print "Press any key to quit"
Print "Press any key to quit"
Sleep</lang>
Sleep</syntaxhighlight>


{{out}}
{{out}}
Line 2,050: Line 2,050:
=={{header|Free Pascal}}==
=={{header|Free Pascal}}==
{{libheader|GMP}}
{{libheader|GMP}}
<lang Delphi>{$mode objFPC}
<syntaxhighlight lang="delphi">{$mode objFPC}


uses
uses
Line 2,130: Line 2,130:
// note, strings longer than 34 characters will be silently clipped
// note, strings longer than 34 characters will be silently clipped
writeLn(isLegal(delSpace('GB82 WEST 1234 5698 7654 32')));
writeLn(isLegal(delSpace('GB82 WEST 1234 5698 7654 32')));
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>TRUE</pre>
<pre>TRUE</pre>
Line 2,136: Line 2,136:
=={{header|Go}}==
=={{header|Go}}==


<lang Go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 2,205: Line 2,205:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Groovy}}==
=={{header|Groovy}}==
<lang groovy>def validateIBAN(String iban) {
<syntaxhighlight lang="groovy">def validateIBAN(String iban) {
def iso = [AL: 28, AD: 24, AT: 20, AZ: 28, BE: 16, BH: 22, BA: 20, BR: 29, BG: 22,
def iso = [AL: 28, AD: 24, AT: 20, AZ: 28, BE: 16, BH: 22, BA: 20, BR: 29, BG: 22,
HR: 21, CY: 28, CZ: 24, DK: 18, DO: 28, EE: 20, FO: 18, FI: 18, FR: 27, GE: 22, DE: 22, GI: 23,
HR: 21, CY: 28, CZ: 24, DK: 18, DO: 28, EE: 20, FO: 18, FI: 18, FR: 27, GE: 22, DE: 22, GI: 23,
Line 2,223: Line 2,223:
def number = iban.collect { Character.digit(it as char, 36) }.join('')
def number = iban.collect { Character.digit(it as char, 36) }.join('')
(number as BigInteger).mod(97) == 1
(number as BigInteger).mod(97) == 1
}</lang>
}</syntaxhighlight>


Testing:
Testing:
<lang groovy>[ 'GB82 WEST 1234 5698 7654 32',
<syntaxhighlight lang="groovy">[ 'GB82 WEST 1234 5698 7654 32',
'GB82 TEST 1234 5698 7654 32',
'GB82 TEST 1234 5698 7654 32',
'GB81 WEST 1234 5698 7654 32',
'GB81 WEST 1234 5698 7654 32',
Line 2,232: Line 2,232:
'CH93 0076 2011 6238 5295 7' ].each { iban ->
'CH93 0076 2011 6238 5295 7' ].each { iban ->
println "$iban is ${validateIBAN(iban) ? 'valid' : 'invalid'}"
println "$iban is ${validateIBAN(iban) ? 'valid' : 'invalid'}"
}</lang>
}</syntaxhighlight>
{{output}}
{{output}}
<pre>GB82 WEST 1234 5698 7654 32 is valid
<pre>GB82 WEST 1234 5698 7654 32 is valid
Line 2,242: Line 2,242:
=={{header|Haskell}}==
=={{header|Haskell}}==
This program uses the Maybe and Either monads to handle failures. Values of type 'Maybe a' can contain 'Nothing' (no value) or 'Just a' (a value of type 'a'). Values of type 'Either a b' contain 'Left b' (usually indicating failure) or 'Right c' (usually indicating success).
This program uses the Maybe and Either monads to handle failures. Values of type 'Maybe a' can contain 'Nothing' (no value) or 'Just a' (a value of type 'a'). Values of type 'Either a b' contain 'Left b' (usually indicating failure) or 'Right c' (usually indicating success).
<lang Haskell>import Data.Char (toUpper)
<syntaxhighlight lang="haskell">import Data.Char (toUpper)
import Data.Maybe (fromJust)
import Data.Maybe (fromJust)


Line 2,294: Line 2,294:


invalidBecause reason = Left $ "Invalid IBAN number " ++ xs ++
invalidBecause reason = Left $ "Invalid IBAN number " ++ xs ++
": " ++ reason</lang>{{out}}
": " ++ reason</syntaxhighlight>{{out}}
<pre>
<pre>
validateIBAN "GB82 WEST 1234 5698 7654 32"
validateIBAN "GB82 WEST 1234 5698 7654 32"
Line 2,316: Line 2,316:


=={{header|IS-BASIC}}==
=={{header|IS-BASIC}}==
<lang IS-BASIC>100 PROGRAM "IBAN.bas"
<syntaxhighlight lang="is-basic">100 PROGRAM "IBAN.bas"
110 STRING CO$(1 TO 93)*2
110 STRING CO$(1 TO 93)*2
120 NUMERIC LG(1 TO 93)
120 NUMERIC LG(1 TO 93)
Line 2,373: Line 2,373:
650 DATA AD,24,AE,23,AL,28,AO,25,AT,20,AZ,28,BA,20,BE,16,BF,28,BG,22,BH,22,BI,16,BJ,28,BR,29,BY,28,CG,27,CH,21,CI,28,CM,27,CR,22,CV,25,CY,28,CZ,24,DE,22,DK,18,DO,28,DZ,24,EE,20,EG,27,ES,24,FI,18,FO,18,FR,27,GA,27,GB,22,GE,22,GI,23,GL,18
650 DATA AD,24,AE,23,AL,28,AO,25,AT,20,AZ,28,BA,20,BE,16,BF,28,BG,22,BH,22,BI,16,BJ,28,BR,29,BY,28,CG,27,CH,21,CI,28,CM,27,CR,22,CV,25,CY,28,CZ,24,DE,22,DK,18,DO,28,DZ,24,EE,20,EG,27,ES,24,FI,18,FO,18,FR,27,GA,27,GB,22,GE,22,GI,23,GL,18
660 DATA GR,27,GT,28,HN,28,HR,21,HU,28,IE,22,IL,23,IR,26,IS,26,IT,27,JO,30,KM,27,KW,30,KZ,20,LB,28,LI,21,LT,20,LU,20,LV,21,MA,28,MC,27,MD,24,ME,22,MG,27,MK,19,ML,28,MR,27,MT,31,MU,30,MZ,25,NE,28,NI,32,NL,18,NO,15,PK,24,PL,28,PS,29,PT,25
660 DATA GR,27,GT,28,HN,28,HR,21,HU,28,IE,22,IL,23,IR,26,IS,26,IT,27,JO,30,KM,27,KW,30,KZ,20,LB,28,LI,21,LT,20,LU,20,LV,21,MA,28,MC,27,MD,24,ME,22,MG,27,MK,19,ML,28,MR,27,MT,31,MU,30,MZ,25,NE,28,NI,32,NL,18,NO,15,PK,24,PL,28,PS,29,PT,25
670 DATA QA,29,RO,24,RS,22,SA,24,SE,24,SI,19,SK,24,SM,27,SN,28,TD,27,TG,28,TL,23,TN,24,TR,26,UA,29,VG,24,XK,20</lang>
670 DATA QA,29,RO,24,RS,22,SA,24,SE,24,SI,19,SK,24,SM,27,SN,28,TD,27,TG,28,TL,23,TN,24,TR,26,UA,29,VG,24,XK,20</syntaxhighlight>


=={{header|J}}==
=={{header|J}}==
<lang J>NB. delete any blank characters
<syntaxhighlight lang="j">NB. delete any blank characters
delblk =. #~ ' '&~:
delblk =. #~ ' '&~:
NB. rearrange
NB. rearrange
Line 2,410: Line 2,410:
NB. IBAN
NB. IBAN
iban =: quads @: ibancheck
iban =: quads @: ibancheck
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
iban 'GB82 WEST 1234 5698 7654 32'
iban 'GB82 WEST 1234 5698 7654 32'
Line 2,425: Line 2,425:
=={{header|Java}}==
=={{header|Java}}==
{{works with|Java|8+}}
{{works with|Java|8+}}
<lang java>import java.math.BigInteger;
<syntaxhighlight lang="java">import java.math.BigInteger;
import java.util.*;
import java.util.*;


Line 2,475: Line 2,475:
return bigInt.mod(BigInteger.valueOf(97)).intValue() == 1;
return bigInt.mod(BigInteger.valueOf(97)).intValue() == 1;
}
}
}</lang>{{out}}
}</syntaxhighlight>{{out}}
<pre>GB82 WEST 1234 5698 7654 32 is valid.
<pre>GB82 WEST 1234 5698 7654 32 is valid.
GB82 TEST 1234 5698 7654 32 is not valid.
GB82 TEST 1234 5698 7654 32 is not valid.
Line 2,487: Line 2,487:


=={{header|JavaScript}}==
=={{header|JavaScript}}==
<lang JavaScript>var ibanLen = {
<syntaxhighlight lang="javascript">var ibanLen = {
NO:15, BE:16, DK:18, FI:18, FO:18, GL:18, NL:18, MK:19,
NO:15, BE:16, DK:18, FI:18, FO:18, GL:18, NL:18, MK:19,
SI:19, AT:20, BA:20, EE:20, KZ:20, LT:20, LU:20, CR:21,
SI:19, AT:20, BA:20, EE:20, KZ:20, LT:20, LU:20, CR:21,
Line 2,514: Line 2,514:
document.write(isValid('GB82 TEST 1234 5698 7654 32'), '<br>') // false
document.write(isValid('GB82 TEST 1234 5698 7654 32'), '<br>') // false
document.write(isValid('SA03 8000 0000 6080 1016 7519'), '<br>') // true
document.write(isValid('SA03 8000 0000 6080 1016 7519'), '<br>') // true
</syntaxhighlight>
</lang>
{{out}}
{{out}}
true
true
Line 2,525: Line 2,525:
This implementation requires a version of jq with <tt>gsub</tt>.
This implementation requires a version of jq with <tt>gsub</tt>.


The heart of the matter consists of just four lines of straightforward jq code:<lang jq>
The heart of the matter consists of just four lines of straightforward jq code:<syntaxhighlight lang="jq">
# strip the input string of spaces and tabs:
# strip the input string of spaces and tabs:
gsub("[ \t]";"")
gsub("[ \t]";"")
Line 2,534: Line 2,534:
# check the mod 97 criterion:
# check the mod 97 criterion:
and ( (.[4:] + .[0:4]) | letters2digits | remainder) == 1
and ( (.[4:] + .[0:4]) | letters2digits | remainder) == 1
</syntaxhighlight>
</lang>
This conciseness is achieved courtesy of the helper functions: <tt>letters2digits</tt> and <tt>remainder</tt>. These could be implemented as inner functions of the main function,
This conciseness is achieved courtesy of the helper functions: <tt>letters2digits</tt> and <tt>remainder</tt>. These could be implemented as inner functions of the main function,
but for clarity they are shown as top-level functions here.
but for clarity they are shown as top-level functions here.
<lang jq>def letters2digits:
<syntaxhighlight lang="jq">def letters2digits:
65 as $A | 90 as $Z
65 as $A | 90 as $Z
| ($A - 10) as $ten
| ($A - 10) as $ten
Line 2,574: Line 2,574:
and length == $lengths[.[0:2]]
and length == $lengths[.[0:2]]
# Shift and convert:
# Shift and convert:
and ( (.[4:] + .[0:4]) | letters2digits | remainder) == 1 ;</lang>Examples<lang jq>
and ( (.[4:] + .[0:4]) | letters2digits | remainder) == 1 ;</syntaxhighlight>Examples<syntaxhighlight lang="jq">
"GB82 WEST 1234 5698 7654 32" | is_valid_iban #=> true
"GB82 WEST 1234 5698 7654 32" | is_valid_iban #=> true
"GB82 TEST 1234 5698 7654 32" | is_valid_iban #=> false</lang>
"GB82 TEST 1234 5698 7654 32" | is_valid_iban #=> false</syntaxhighlight>


=={{header|Jsish}}==
=={{header|Jsish}}==
From the Javascript entry.
From the Javascript entry.
<lang javascript>var ibanLen = {
<syntaxhighlight lang="javascript">var ibanLen = {
NO:15, BE:16, DK:18, FI:18, FO:18, GL:18, NL:18, MK:19,
NO:15, BE:16, DK:18, FI:18, FO:18, GL:18, NL:18, MK:19,
SI:19, AT:20, BA:20, EE:20, KZ:20, LT:20, LU:20, CR:21,
SI:19, AT:20, BA:20, EE:20, KZ:20, LT:20, LU:20, CR:21,
Line 2,617: Line 2,617:
isIBAN('SA03 8000 0000 6080 1016 7519') ==> true
isIBAN('SA03 8000 0000 6080 1016 7519') ==> true
=!EXPECTEND!=
=!EXPECTEND!=
*/</lang>
*/</syntaxhighlight>


{{out}}
{{out}}
Line 2,626: Line 2,626:
{{works with|Julia|0.6}}
{{works with|Julia|0.6}}


<lang julia>function validiban(iban::AbstractString)
<syntaxhighlight lang="julia">function validiban(iban::AbstractString)
country2length = Dict(
country2length = Dict(
"AL" => 28, "AD" => 24, "AT" => 20, "AZ" => 28, "BE" => 16, "BH" => 22, "BA" => 20, "BR" => 29,
"AL" => 28, "AD" => 24, "AT" => 20, "AZ" => 28, "BE" => 16, "BH" => 22, "BA" => 20, "BR" => 29,
Line 2,647: Line 2,647:
digs = parse(BigInt, join(parse(Int, ch, 36) for ch in iban))
digs = parse(BigInt, join(parse(Int, ch, 36) for ch in iban))
return rst && digs % 97 == 1
return rst && digs % 97 == 1
end</lang>
end</syntaxhighlight>


{{out}}
{{out}}
Line 2,654: Line 2,654:


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>// version 1.0.6
<syntaxhighlight lang="scala">// version 1.0.6


import java.math.BigInteger
import java.math.BigInteger
Line 2,697: Line 2,697:
println(iban + if (valid) " may be valid" else " is not valid")
println(iban + if (valid) " may be valid" else " is not valid")
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,706: Line 2,706:


=={{header|Lobster}}==
=={{header|Lobster}}==
<syntaxhighlight lang="lobster">
<lang Lobster>
let cc = ["AD","AE","AL","AO","AT","AZ","BA","BE","BF","BG","BH","BI","BJ","BR","CG","CH","CI","CM","CR","CV","CY",
let cc = ["AD","AE","AL","AO","AT","AZ","BA","BE","BF","BG","BH","BI","BJ","BR","CG","CH","CI","CM","CR","CV","CY",
"CZ","DE","DK","DO","DZ","EE","EG","ES","FI","FO","FR","GA","GB","GE","GI","GL","GR","GT","HR","HU","IE",
"CZ","DE","DK","DO","DZ","EE","EG","ES","FI","FO","FR","GA","GB","GE","GI","GL","GR","GT","HR","HU","IE",
Line 2,766: Line 2,766:
assert not isValidIBAN("GB82 TEST 1234 5698 7654 32")
assert not isValidIBAN("GB82 TEST 1234 5698 7654 32")
assert not isValidIBAN("GB82 WEST 1243 5698 7654 32")
assert not isValidIBAN("GB82 WEST 1243 5698 7654 32")
</syntaxhighlight>
</lang>


=={{header|Logtalk}}==
=={{header|Logtalk}}==
<lang logtalk>
<syntaxhighlight lang="logtalk">
:- object(iban).
:- object(iban).


Line 2,899: Line 2,899:


:- end_object.
:- end_object.
</syntaxhighlight>
</lang>
Testing:
Testing:
<lang logtalk>
<syntaxhighlight lang="logtalk">
| ?- iban::valid("GB82 WEST 1234 5698 7654 32").
| ?- iban::valid("GB82 WEST 1234 5698 7654 32").
yes
yes
</syntaxhighlight>
</lang>


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>local length=
<syntaxhighlight lang="lua">local length=
{
{
AL=28, AD=24, AT=20, AZ=28, BH=22, BE=16, BA=20, BR=29, BG=22, CR=21,
AL=28, AD=24, AT=20, AZ=28, BH=22, BE=16, BA=20, BR=29, BG=22, CR=21,
Line 2,930: Line 2,930:
end
end
return mod==1
return mod==1
end</lang>
end</syntaxhighlight>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
We make a lambda function which return a string, with the input IBAN plus (Valid) or (Invalid) at the end.
We make a lambda function which return a string, with the input IBAN plus (Valid) or (Invalid) at the end.


<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
\\ IBAN checker
\\ IBAN checker
Function MakeIBANfun$ {
Function MakeIBANfun$ {
Line 2,977: Line 2,977:
Print IbanCheck$("GR16 0110 1250 0000 0001 2300 695X")
Print IbanCheck$("GR16 0110 1250 0000 0001 2300 695X")
Print IbanCheck$("MK11 2222 3333 4444 555")
Print IbanCheck$("MK11 2222 3333 4444 555")
</syntaxhighlight>
</lang>


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>CountryCodes={{"AL",28},{"AD",24},{"AT",20},{"AZ",28},{"BE",16},{"BH",22},{"BA",20},{"BR",29},{"BG",22},{"CR",21},{"HR",21},{"CY",28},{"CZ",24},{"DK",18},{"DO",28},{"EE",20},{"FO",18},{"FI",18},{"FR",27},{"GE",22},{"DE",22},{"GI",23},{"GR",27},{"GL",18},{"GT",28},{"HU",28},{"IS",26},{"IE",22},{"IL",23},{"IT",27},{"KZ",20},{"KW",30},{"LV",21},{"LB",28},{"LI",21},{"LT",20},{"LU",20},{"MK",19},{"MT",31},{"MR",27},{"MU",30},{"MC",27},{"MD",24},{"ME",22},{"NL",18},{"NO",15},{"PK",24},{"PS",29},{"PL",28},{"PT",25},{"RO",24},{"SM",27},{"SA",24},{"RS",22},{"SK",24},{"SI",19},{"ES",24},{"SE",24},{"CH",21},{"TN",24},{"TR",26},{"AE",23},{"GB",22},{"VG",24}};
<syntaxhighlight lang="mathematica">CountryCodes={{"AL",28},{"AD",24},{"AT",20},{"AZ",28},{"BE",16},{"BH",22},{"BA",20},{"BR",29},{"BG",22},{"CR",21},{"HR",21},{"CY",28},{"CZ",24},{"DK",18},{"DO",28},{"EE",20},{"FO",18},{"FI",18},{"FR",27},{"GE",22},{"DE",22},{"GI",23},{"GR",27},{"GL",18},{"GT",28},{"HU",28},{"IS",26},{"IE",22},{"IL",23},{"IT",27},{"KZ",20},{"KW",30},{"LV",21},{"LB",28},{"LI",21},{"LT",20},{"LU",20},{"MK",19},{"MT",31},{"MR",27},{"MU",30},{"MC",27},{"MD",24},{"ME",22},{"NL",18},{"NO",15},{"PK",24},{"PS",29},{"PL",28},{"PT",25},{"RO",24},{"SM",27},{"SA",24},{"RS",22},{"SK",24},{"SI",19},{"ES",24},{"SE",24},{"CH",21},{"TN",24},{"TR",26},{"AE",23},{"GB",22},{"VG",24}};
ClearAll[IBANVerify]
ClearAll[IBANVerify]
IBANVerify[input_String]:=Module[{i,cc,rules},
IBANVerify[input_String]:=Module[{i,cc,rules},
Line 3,008: Line 3,008:
False
False
]
]
]</lang>
]</syntaxhighlight>
Trying out the function:
Trying out the function:
<lang Mathematica>IBANVerify["GB82 WEST 1234 5698 7654 32"]
<syntaxhighlight lang="mathematica">IBANVerify["GB82 WEST 1234 5698 7654 32"]
IBANVerify["GB82 WEST 1234 5698 7654 323"]
IBANVerify["GB82 WEST 1234 5698 7654 323"]
IBANVerify["GB82 WEST 1234 5698 7654 31"]
IBANVerify["GB82 WEST 1234 5698 7654 31"]
IBANVerify["XX82 WEST 1234 5698 7654 323"]</lang>{{out}}
IBANVerify["XX82 WEST 1234 5698 7654 323"]</syntaxhighlight>{{out}}
True
True
False
False
Line 3,021: Line 3,021:
=={{header|MATLAB}}==
=={{header|MATLAB}}==
Didn't check country codes, lengths, or consistent checksums to keep this applicable to any new countries.
Didn't check country codes, lengths, or consistent checksums to keep this applicable to any new countries.
<lang MATLAB>function valid = validateIBAN(iban)
<syntaxhighlight lang="matlab">function valid = validateIBAN(iban)
% Determine if International Bank Account Number is valid IAW ISO 13616
% Determine if International Bank Account Number is valid IAW ISO 13616
% iban - string containing account number
% iban - string containing account number
Line 3,050: Line 3,050:
i2 = min(i1+8, nDig);
i2 = min(i1+8, nDig);
end
end
end</lang>Usage:
end</syntaxhighlight>Usage:
<lang MATLAB>tests = {'GB82 WEST 1234 5698 7654 32' ;
<syntaxhighlight lang="matlab">tests = {'GB82 WEST 1234 5698 7654 32' ;
'GB82 TEST 1234 5698 7654 32' ;
'GB82 TEST 1234 5698 7654 32' ;
'CH93 0076 2011 6238 5295 7' ;
'CH93 0076 2011 6238 5295 7' ;
Line 3,061: Line 3,061:
for k = 1:length(tests)
for k = 1:length(tests)
fprintf('%s -> %svalid\n', tests{k}, char(~validateIBAN(tests{k}).*'in'))
fprintf('%s -> %svalid\n', tests{k}, char(~validateIBAN(tests{k}).*'in'))
end</lang>{{out}}
end</syntaxhighlight>{{out}}
<pre>GB82 WEST 1234 5698 7654 32 -> valid
<pre>GB82 WEST 1234 5698 7654 32 -> valid
GB82 TEST 1234 5698 7654 32 -> invalid
GB82 TEST 1234 5698 7654 32 -> invalid
Line 3,072: Line 3,072:


=={{header|NewLISP}}==
=={{header|NewLISP}}==
<syntaxhighlight lang="newlisp">
<lang NewLISP>
(setq *iban-code-length* '((15 ("NO"))
(setq *iban-code-length* '((15 ("NO"))
(16 ("BE"))
(16 ("BE"))
Line 3,140: Line 3,140:
)
)
)
)
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 3,152: Line 3,152:
=={{header|Nim}}==
=={{header|Nim}}==
{{libheader|bigints}}
{{libheader|bigints}}
<lang nim>import tables, strutils, re, bigints
<syntaxhighlight lang="nim">import tables, strutils, re, bigints


let countryLen = toTable({
let countryLen = toTable({
Line 3,185: Line 3,185:


for account in ["GB82 WEST 1234 5698 7654 32", "GB82 TEST 1234 5698 7654 32"]:
for account in ["GB82 WEST 1234 5698 7654 32", "GB82 TEST 1234 5698 7654 32"]:
echo account, " validation is: ", validIban account</lang>{{out}}
echo account, " validation is: ", validIban account</syntaxhighlight>{{out}}
GB82 WEST 1234 5698 7654 32 validation is: true
GB82 WEST 1234 5698 7654 32 validation is: true
GB82 TEST 1234 5698 7654 32 validation is: false
GB82 TEST 1234 5698 7654 32 validation is: false
Line 3,191: Line 3,191:
=={{header|Oberon-2}}==
=={{header|Oberon-2}}==
Works with oo2c Version 2
Works with oo2c Version 2
<lang oberon2>
<syntaxhighlight lang="oberon2">
MODULE IBAN;
MODULE IBAN;
IMPORT
IMPORT
Line 3,353: Line 3,353:
Test;
Test;
END IBAN.
END IBAN.
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 3,364: Line 3,364:
=={{header|OCaml}}==
=={{header|OCaml}}==
{{works with|OCaml|4.03+}}
{{works with|OCaml|4.03+}}
<lang ocaml>
<syntaxhighlight lang="ocaml">
#load "str.cma"
#load "str.cma"
#load "nums.cma" (* for module Big_int *)
#load "nums.cma" (* for module Big_int *)
Line 3,471: Line 3,471:
in
in
List.iter (fun pair -> testit pair) ibans
List.iter (fun pair -> testit pair) ibans
</syntaxhighlight>
</lang>
{{out}}
{{out}}
GB82 WEST 1234 5698 7654 32 is valid. Expected true [PASS]
GB82 WEST 1234 5698 7654 32 is valid. Expected true [PASS]
Line 3,482: Line 3,482:


=={{header|Perl}}==
=={{header|Perl}}==
<lang Perl>#!/usr/bin/perl
<syntaxhighlight lang="perl">#!/usr/bin/perl
use strict ;
use strict ;
use warnings ;
use warnings ;
Line 3,529: Line 3,529:
if ( validate_iban( "GB82TEST12345698765432" ) ) {
if ( validate_iban( "GB82TEST12345698765432" ) ) {
print "GB82TEST12345698765432 is valid!\n" ;
print "GB82TEST12345698765432 is valid!\n" ;
}</lang>{{out}}
}</syntaxhighlight>{{out}}
GB82 WEST 1234 5698 7654 32 is a valid IBAN number!
GB82 WEST 1234 5698 7654 32 is a valid IBAN number!
GB82TEST12345698765432 is invalid!
GB82TEST12345698765432 is invalid!


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\IBAN.exw
-- demo\rosetta\IBAN.exw
Line 3,594: Line 3,594:
<span style="color: #000000;">test</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"SA03 8000 0000 6080 1016 7519"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">test</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"SA03 8000 0000 6080 1016 7519"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">test</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"CH93 0076 2011 6238 5295 7"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">test</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"CH93 0076 2011 6238 5295 7"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 3,605: Line 3,605:


=={{header|PHP}}==
=={{header|PHP}}==
<lang php>
<syntaxhighlight lang="php">
<?php
<?php


Line 3,685: Line 3,685:
echo "IBAN NOT VALID";
echo "IBAN NOT VALID";
}
}
</syntaxhighlight>
</lang>


=={{header|Picat}}==
=={{header|Picat}}==
<lang Picat>go =>
<syntaxhighlight lang="picat">go =>
IBAN = "GB82 WEST 1234 5698 7654 32",
IBAN = "GB82 WEST 1234 5698 7654 32",
println(IBAN=iban(IBAN)),
println(IBAN=iban(IBAN)),
Line 3,721: Line 3,721:
"MR"=27, "MU"=30, "MC"=27, "MD"=24, "ME"=22, "NL"=18, "NO"=15, "PK"=24, "PS"=29, "PL"=28,
"MR"=27, "MU"=30, "MC"=27, "MD"=24, "ME"=22, "NL"=18, "NO"=15, "PK"=24, "PS"=29, "PL"=28,
"PT"=25, "QA"=29, "RO"=24, "SM"=27, "SA"=24, "RS"=22, "SK"=24, "SI"=19, "ES"=24, "SE"=24,
"PT"=25, "QA"=29, "RO"=24, "SM"=27, "SA"=24, "RS"=22, "SK"=24, "SI"=19, "ES"=24, "SE"=24,
"CH"=21, "TN"=24, "TR"=26, "AE"=23, "GB"=22, "VG"=24]).</lang>
"CH"=21, "TN"=24, "TR"=26, "AE"=23, "GB"=22, "VG"=24]).</syntaxhighlight>


{{out}}
{{out}}
Line 3,727: Line 3,727:


===Some more (and interesting) tests===
===Some more (and interesting) tests===
<lang Picat>go2 =>
<syntaxhighlight lang="picat">go2 =>
Ibans = ["GB82 WEST 1234 5698 7654 32",
Ibans = ["GB82 WEST 1234 5698 7654 32",
"gb82 WEST 1234 5698 7654 32",
"gb82 WEST 1234 5698 7654 32",
Line 3,745: Line 3,745:
println(IBAN=iban(IBAN))
println(IBAN=iban(IBAN))
end,
end,
nl.</lang>
nl.</syntaxhighlight>


{{out}}
{{out}}
Line 3,762: Line 3,762:


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang Picolisp>(setq *Sizes '((GB . 22) (CH . 21) (SA . 24)))
<syntaxhighlight lang="picolisp">(setq *Sizes '((GB . 22) (CH . 21) (SA . 24)))


(de iban (Str)
(de iban (Str)
Line 3,791: Line 3,791:
(println 'Invalid) ) )
(println 'Invalid) ) )


(bye)</lang>
(bye)</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
<lang PowerShell>
function verifIBAN ([string]$ibanS)
function verifIBAN ([string]$ibanS)
{
{
Line 3,821: Line 3,821:
}
}
} #fin fonction vérification IBAN / Stéphane RABANY 2018
} #fin fonction vérification IBAN / Stéphane RABANY 2018
</syntaxhighlight>
</lang>


Ancien texte qui ne sert à rien selon moi :
Ancien texte qui ne sert à rien selon moi :
I have heard that Regex should not be used with IBAN codes. Regex does seem to work, however.
I have heard that Regex should not be used with IBAN codes. Regex does seem to work, however.
<syntaxhighlight lang="powershell">
<lang PowerShell>
@'
@'
"Country","Length","Example"
"Country","Length","Example"
Line 3,886: Line 3,886:


$ibans
$ibans
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 3,939: Line 3,939:
United Kingdom GB 22 GB29NWBK60161331926819
United Kingdom GB 22 GB29NWBK60161331926819
</pre>
</pre>
<syntaxhighlight lang="powershell">
<lang PowerShell>
$regex = [regex]'[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{6}[0-9]{5}([a-zA-Z0-9]?){0,16}'
$regex = [regex]'[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{6}[0-9]{5}([a-zA-Z0-9]?){0,16}'


Line 3,950: Line 3,950:
}
}
}
}
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 4,005: Line 4,005:


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang purebasic>EnableExplicit
<syntaxhighlight lang="purebasic">EnableExplicit
Enumeration IBAN
Enumeration IBAN
#IBAN_VAL
#IBAN_VAL
Line 4,096: Line 4,096:
ForEver
ForEver
Input()
Input()
End</lang>
End</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 4,115: Line 4,115:
=={{header|Python}}==
=={{header|Python}}==
{{trans|Ruby}}
{{trans|Ruby}}
<lang python>import re
<syntaxhighlight lang="python">import re


_country2length = dict(
_country2length = dict(
Line 4,142: Line 4,142:
if __name__ == '__main__':
if __name__ == '__main__':
for account in ["GB82 WEST 1234 5698 7654 32", "GB82 TEST 1234 5698 7654 32"]:
for account in ["GB82 WEST 1234 5698 7654 32", "GB82 TEST 1234 5698 7654 32"]:
print('%s validation is: %s' % (account, valid_iban(account)))</lang>{{out}}
print('%s validation is: %s' % (account, valid_iban(account)))</syntaxhighlight>{{out}}
GB82 WEST 1234 5698 7654 32 validation is: True
GB82 WEST 1234 5698 7654 32 validation is: True
GB82 TEST 1234 5698 7654 32 validation is: False
GB82 TEST 1234 5698 7654 32 validation is: False


=={{header|Racket}}==
=={{header|Racket}}==
<lang racket>#lang racket
<syntaxhighlight lang="racket">#lang racket
(define lens
(define lens
'([AL 28] [AD 24] [AT 20] [AZ 28] [BH 22] [BE 16] [BA 20] [BR 29] [BG 22]
'([AL 28] [AD 24] [AT 20] [AZ 28] [BH 22] [BE 16] [BA 20] [BR 29] [BG 22]
Line 4,171: Line 4,171:


(valid-iban? "GB82 WEST 1234 5698 7654 32") ; => #t
(valid-iban? "GB82 WEST 1234 5698 7654 32") ; => #t
(valid-iban? "GB82 TEST 1234 5698 7654 32") ; => #f</lang>
(valid-iban? "GB82 TEST 1234 5698 7654 32") ; => #f</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
<lang perl6>subset IBAN of Str where sub ($_ is copy) {
<syntaxhighlight lang="raku" line>subset IBAN of Str where sub ($_ is copy) {
s:g/\s//;
s:g/\s//;
return False if m/<-[ 0..9 A..Z a..z ]>/ or .chars != <
return False if m/<-[ 0..9 A..Z a..z ]>/ or .chars != <
Line 4,193: Line 4,193:
'GB82 WEST 1234 5698 7654 32',
'GB82 WEST 1234 5698 7654 32',
'gb82 west 1234 5698 7654 32',
'gb82 west 1234 5698 7654 32',
'GB82 TEST 1234 5698 7654 32';</lang>{{out}}
'GB82 TEST 1234 5698 7654 32';</syntaxhighlight>{{out}}
GB82 WEST 1234 5698 7654 32 is valid.
GB82 WEST 1234 5698 7654 32 is valid.
gb82 west 1234 5698 7654 32 is valid.
gb82 west 1234 5698 7654 32 is valid.
Line 4,201: Line 4,201:
These REXX programs can validate an IBAN specified on the command line or from an internal list.
These REXX programs can validate an IBAN specified on the command line or from an internal list.
===basic checking===
===basic checking===
<lang rexx>/*REXX program validates an IBAN (International Bank Account Number). */
<syntaxhighlight lang="rexx">/*REXX program validates an IBAN (International Bank Account Number). */
@.=; @.1 = 'GB82 WEST 1234 5698 7654 32 '
@.=; @.1 = 'GB82 WEST 1234 5698 7654 32 '
@.2 = 'Gb82 West 1234 5698 7654 32 '
@.2 = 'Gb82 West 1234 5698 7654 32 '
Line 4,245: Line 4,245:


if z//97==1 then return 0 /*check if correct remainder (modulus).*/
if z//97==1 then return 0 /*check if correct remainder (modulus).*/
return e 'check digits.'</lang>
return e 'check digits.'</syntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}
<pre>
<pre>
Line 4,265: Line 4,265:
:* checks for two countries that may not be valid (as per their entry date into the IBAN system)
:* checks for two countries that may not be valid (as per their entry date into the IBAN system)
:* checks some countries to make sure their check digits match a specific value
:* checks some countries to make sure their check digits match a specific value
<lang rexx>/*REXX pgm validates an IBAN (International Bank Account Number), including date ranges.*/
<syntaxhighlight lang="rexx">/*REXX pgm validates an IBAN (International Bank Account Number), including date ranges.*/
@.=; @.1 = 'GB82 WEST 1234 5698 7654 32 '
@.=; @.1 = 'GB82 WEST 1234 5698 7654 32 '
@.2 = 'Gb82 West 1234 5698 7654 32 '
@.2 = 'Gb82 West 1234 5698 7654 32 '
Line 4,318: Line 4,318:


if z//97==1 then return 0 /*check if correct remainder (modulus).*/
if z//97==1 then return 0 /*check if correct remainder (modulus).*/
return e 'check digits.'</lang>
return e 'check digits.'</syntaxhighlight>
{{out|output|text=&nbsp; when using the default input, &nbsp; (the run date of this program is &nbsp; 29-April-2013):}}
{{out|output|text=&nbsp; when using the default input, &nbsp; (the run date of this program is &nbsp; 29-April-2013):}}
<pre>
<pre>
Line 4,337: Line 4,337:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
# Project : IBAN
# Project : IBAN


Line 4,390: Line 4,390:
modnew = number(modnew) % 97
modnew = number(modnew) % 97
return modnew
return modnew
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 4,402: Line 4,402:
=={{header|Ruby}}==
=={{header|Ruby}}==
{{works with|Ruby|1.9+}}
{{works with|Ruby|1.9+}}
<lang Ruby>def valid_iban? iban
<syntaxhighlight lang="ruby">def valid_iban? iban
len = {
len = {
AL: 28, AD: 24, AT: 20, AZ: 28, BE: 16, BH: 22, BA: 20, BR: 29,
AL: 28, AD: 24, AT: 20, AZ: 28, BE: 16, BH: 22, BA: 20, BR: 29,
Line 4,430: Line 4,430:


p valid_iban? "GB82 WEST 1234 5698 7654 32" #=> true
p valid_iban? "GB82 WEST 1234 5698 7654 32" #=> true
p valid_iban? "GB82 TEST 1234 5698 7654 32" #=> false</lang>
p valid_iban? "GB82 TEST 1234 5698 7654 32" #=> false</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
<syntaxhighlight lang="rust">
<lang Rust>
fn main() {
fn main() {
for iban in [
for iban in [
Line 4,499: Line 4,499:
}) == 1
}) == 1
}
}
</syntaxhighlight>
</lang>


=={{header|Scala}}==
=={{header|Scala}}==
{{libheader|Scala}}<lang Scala>import scala.collection.immutable.SortedMap
{{libheader|Scala}}<syntaxhighlight lang="scala">import scala.collection.immutable.SortedMap


class Iban(val iban: String) {
class Iban(val iban: String) {
Line 4,546: Line 4,546:


def apply(s: String) = new Iban(s.replaceAll( """\s""", ""))
def apply(s: String) = new Iban(s.replaceAll( """\s""", ""))
}</lang>The test program:
}</syntaxhighlight>The test program:
<lang Scala>object IbanTest extends App {
<syntaxhighlight lang="scala">object IbanTest extends App {
def blackCases = """AT611904300235473201
def blackCases = """AT611904300235473201
|GB82TEST12345698765432
|GB82TEST12345698765432
Line 4,644: Line 4,644:
blackCases.lines.foreach(l => assert(!Iban(l).isValidIban))
blackCases.lines.foreach(l => assert(!Iban(l).isValidIban))
println(s"Successfully completed; ${whiteCases.lines.size + blackCases.lines.size} cases tested, no errors.")
println(s"Successfully completed; ${whiteCases.lines.size + blackCases.lines.size} cases tested, no errors.")
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
Successfully completed; 91 cases tested, no errors.
Successfully completed; 91 cases tested, no errors.


=={{header|Seed7}}==
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "bigint.s7i";
include "bigint.s7i";


Line 4,705: Line 4,705:
check("GB82 TEST 1234 5698 7654 32");
check("GB82 TEST 1234 5698 7654 32");
check("GB82 WEST 1243 5698 7654 32");
check("GB82 WEST 1243 5698 7654 32");
end func;</lang>
end func;</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 4,716: Line 4,716:


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>func valid_iban(iban) {
<syntaxhighlight lang="ruby">func valid_iban(iban) {
static len = Hash(
static len = Hash(
AD=>24, AE=>23, AL=>28, AO=>25, AT=>20, AZ=>28, BA=>20, BE=>16, BF=>27,
AD=>24, AE=>23, AL=>28, AO=>25, AT=>20, AZ=>28, BA=>20, BE=>16, BF=>27,
Line 4,746: Line 4,746:


say valid_iban("GB82 WEST 1234 5698 7654 32") #=> true
say valid_iban("GB82 WEST 1234 5698 7654 32") #=> true
say valid_iban("GB82 TEST 1234 5698 7654 32") #=> false</lang>
say valid_iban("GB82 TEST 1234 5698 7654 32") #=> false</syntaxhighlight>


=={{header|SNOBOL4}}==
=={{header|SNOBOL4}}==
<lang SNOBOL4>* IBAN - International Bank Account Number validation
<syntaxhighlight lang="snobol4">* IBAN - International Bank Account Number validation
DEFINE('ibantable()') :(iban_table_end)
DEFINE('ibantable()') :(iban_table_end)
ibantable
ibantable
Line 4,829: Line 4,829:


OUTPUT = "valid IBAN: " line :(read)
OUTPUT = "valid IBAN: " line :(read)
END</lang>
END</syntaxhighlight>


'''Output:'''
'''Output:'''
Line 4,849: Line 4,849:
{{works with|SML/NJ}}
{{works with|SML/NJ}}


<lang sml>(* country_code : string -> int *)
<syntaxhighlight lang="sml">(* country_code : string -> int *)
(* Get the length of a valid IBAN given the two chars long country code *)
(* Get the length of a valid IBAN given the two chars long country code *)
fun country_code (str : string) : int =
fun country_code (str : string) : int =
Line 4,915: Line 4,915:
IntInf.mod (number, 97) = 1
IntInf.mod (number, 97) = 1
end
end
end handle Subscript => false | Domain => false</lang>
end handle Subscript => false | Domain => false</syntaxhighlight>


{{output}}
{{output}}
Line 4,924: Line 4,924:


=={{header|Tcl}}==
=={{header|Tcl}}==
<lang tcl>proc verifyIBAN {iban} {
<syntaxhighlight lang="tcl">proc verifyIBAN {iban} {
# Normalize by up-casing and stripping illegal chars (e.g., space)
# Normalize by up-casing and stripping illegal chars (e.g., space)
set iban [regsub -all {[^A-Z0-9]+} [string toupper $iban] ""]
set iban [regsub -all {[^A-Z0-9]+} [string toupper $iban] ""]
Line 4,957: Line 4,957:
# Verify length and modulus
# Verify length and modulus
return [expr {[string length $iban] == $len && $num % 97 == 1}]
return [expr {[string length $iban] == $len && $num % 97 == 1}]
}</lang>Demonstrating:
}</syntaxhighlight>Demonstrating:
<lang tcl>set iban "GB82 WEST 1234 5698 7654 32"
<syntaxhighlight lang="tcl">set iban "GB82 WEST 1234 5698 7654 32"
puts "$iban is [expr {[verifyIBAN $iban] ? {verified} : {unverified}}]"
puts "$iban is [expr {[verifyIBAN $iban] ? {verified} : {unverified}}]"
set not "GB42 WEST 1234 5698 7654 32"
set not "GB42 WEST 1234 5698 7654 32"
puts "$not is [expr {[verifyIBAN $not] ? {verified} : {unverified}}]"</lang>{{out}}
puts "$not is [expr {[verifyIBAN $not] ? {verified} : {unverified}}]"</syntaxhighlight>{{out}}
<pre>GB82 WEST 1234 5698 7654 32 is verified
<pre>GB82 WEST 1234 5698 7654 32 is verified
GB42 WEST 1234 5698 7654 32 is unverified</pre>
GB42 WEST 1234 5698 7654 32 is unverified</pre>
Line 4,968: Line 4,968:
{{works with|bash}}
{{works with|bash}}
This does not verify the country code or the length.
This does not verify the country code or the length.
<lang bash>declare -A base36=(
<syntaxhighlight lang="bash">declare -A base36=(
[A]=10 [B]=11 [C]=12 [D]=13 [E]=14 [F]=15 [G]=16 [H]=17 [I]=18
[A]=10 [B]=11 [C]=12 [D]=13 [E]=14 [F]=15 [G]=16 [H]=17 [I]=18
[J]=19 [K]=20 [L]=21 [M]=22 [N]=23 [O]=24 [P]=25 [Q]=26 [R]=27
[J]=19 [K]=20 [L]=21 [M]=22 [N]=23 [O]=24 [P]=25 [Q]=26 [R]=27
Line 5,001: Line 5,001:
printf "%s : " "$test"
printf "%s : " "$test"
is_iban "$test" && echo yes || echo no
is_iban "$test" && echo yes || echo no
done</lang>
done</syntaxhighlight>


{{output}}
{{output}}
Line 5,008: Line 5,008:


=={{header|VBA}}==
=={{header|VBA}}==
{{trans|Phix}}<lang vb>Public nations As New Collection
{{trans|Phix}}<syntaxhighlight lang="vb">Public nations As New Collection
Private Sub init()
Private Sub init()
nations.Add 24, "AD"
nations.Add 24, "AD"
Line 5,087: Line 5,087:
test "SA03 8000 0000 6080 1016 7519", True
test "SA03 8000 0000 6080 1016 7519", True
test "CH93 0076 2011 6238 5295 7", True
test "CH93 0076 2011 6238 5295 7", True
End Sub</lang>{{out}}
End Sub</syntaxhighlight>{{out}}
<pre>GB82WEST12345698765432 ok
<pre>GB82WEST12345698765432 ok
GB82TEST12345698765432 invalid (as expected)
GB82TEST12345698765432 invalid (as expected)
Line 5,095: Line 5,095:


=={{header|VBScript}}==
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
Function validate_iban(s)
Function validate_iban(s)
validate_iban = Chr(34) & s & Chr(34) & " is NOT valid."
validate_iban = Chr(34) & s & Chr(34) & " is NOT valid."
Line 5,154: Line 5,154:
WScript.StdOut.WriteLine validate_iban("US12 3456 7890 0987 6543 210")
WScript.StdOut.WriteLine validate_iban("US12 3456 7890 0987 6543 210")
WScript.StdOut.WriteLine validate_iban("GR16 0110 1250 0000 0001 2300 695X")
WScript.StdOut.WriteLine validate_iban("GR16 0110 1250 0000 0001 2300 695X")
</syntaxhighlight>
</lang>


{{Out}}
{{Out}}
Line 5,175: Line 5,175:
{{trans|Kotlin}}
{{trans|Kotlin}}
{{libheader|Wren-big}}
{{libheader|Wren-big}}
<lang ecmascript>import "/big" for BigInt
<syntaxhighlight lang="ecmascript">import "/big" for BigInt


var countryCodes =
var countryCodes =
Line 5,212: Line 5,212:
var valid = isValid.call(iban)
var valid = isValid.call(iban)
System.print(iban + (valid ? " may be valid" : " is not valid"))
System.print(iban + (valid ? " may be valid" : " is not valid"))
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 5,222: Line 5,222:
=={{header|Yabasic}}==
=={{header|Yabasic}}==
{{trans|Phix}}
{{trans|Phix}}
<lang Yabasic>// List updated to release 72, 25 November 2016, of IBAN Registry (75 countries)
<syntaxhighlight lang="yabasic">// List updated to release 72, 25 November 2016, of IBAN Registry (75 countries)
countryCodes$ = "AD24 AE23 AL28 AT20 AZ28 BA20 BE16 BG22 BH22 BR29 BY28 CH21 CR22 CY28 CZ24 DE22 "
countryCodes$ = "AD24 AE23 AL28 AT20 AZ28 BA20 BE16 BG22 BH22 BR29 BY28 CH21 CR22 CY28 CZ24 DE22 "
countryCodes$ = countryCodes$ + "DK18 DO28 EE20 ES24 FI18 FO18 FR27 GB22 GE22 GI23 GL18 GR27 GT28 HR21 HU28 IE22 "
countryCodes$ = countryCodes$ + "DK18 DO28 EE20 ES24 FI18 FO18 FR27 GB22 GE22 GI23 GL18 GR27 GT28 HR21 HU28 IE22 "
Line 5,294: Line 5,294:
test("GB81 WEST 1234 5698 7654 32", false)
test("GB81 WEST 1234 5698 7654 32", false)
test("SA03 8000 0000 6080 1016 7519", true)
test("SA03 8000 0000 6080 1016 7519", true)
test("CH93 0076 2011 6238 5295 7", true)</lang>
test("CH93 0076 2011 6238 5295 7", true)</syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==
Using GMP big nums:
Using GMP big nums:
<lang zkl>var BN=Import("zklBigNum");
<syntaxhighlight lang="zkl">var BN=Import("zklBigNum");
fcn validateIBAN(iban){
fcn validateIBAN(iban){
iban=iban-" \t";
iban=iban-" \t";
alphaNums.matches(iban) and (ibans.find(iban[0,2])==iban.len()) and
alphaNums.matches(iban) and (ibans.find(iban[0,2])==iban.len()) and
( BN((iban[4,*]+iban[0,4]).apply("toInt",36)) % 97 == 1 )
( BN((iban[4,*]+iban[0,4]).apply("toInt",36)) % 97 == 1 )
}</lang>Without using big nums:
}</syntaxhighlight>Without using big nums:
<lang zkl>fcn validateIBAN(iban){
<syntaxhighlight lang="zkl">fcn validateIBAN(iban){
iban=iban-" \t";
iban=iban-" \t";
alphaNums.matches(iban) and (ibans.find(iban[0,2])==iban.len()) and
alphaNums.matches(iban) and (ibans.find(iban[0,2])==iban.len()) and
Line 5,315: Line 5,315:
}
}
M
M
}</lang><lang zkl>var alphaNums=RegExp("^[0-9A-Z]+$");
}</syntaxhighlight><syntaxhighlight lang="zkl">var alphaNums=RegExp("^[0-9A-Z]+$");
var ibans= // Dictionary("AD":24, ...)
var ibans= // Dictionary("AD":24, ...)
("AD24 AE23 AL28 AO25 AT20 AZ28 BA20 BE16 BF27 BG22 BH22 BI16 "
("AD24 AE23 AL28 AO25 AT20 AZ28 BA20 BE16 BF27 BG22 BH22 BI16 "
Line 5,324: Line 5,324:
"MR27 MT31 MU30 MZ25 NL18 NO15 PK24 PL28 PS29 PT25 QA29 RO24 "
"MR27 MT31 MU30 MZ25 NL18 NO15 PK24 PL28 PS29 PT25 QA29 RO24 "
"RS22 SA24 SE24 SI19 SK24 SM27 SN28 TN24 TR26 UA29 VG24")
"RS22 SA24 SE24 SI19 SK24 SM27 SN28 TN24 TR26 UA29 VG24")
.split(" ").pump(D(),fcn(w){return(w[0,2],w[2,*].toInt())});</lang>Testing 1 2 3
.split(" ").pump(D(),fcn(w){return(w[0,2],w[2,*].toInt())});</syntaxhighlight>Testing 1 2 3
<lang zkl> // all valid
<syntaxhighlight lang="zkl"> // all valid
T("GB82 WEST 1234 5698 7654 32","GB82WEST12345698765432",
T("GB82 WEST 1234 5698 7654 32","GB82WEST12345698765432",
"GR16 0110 1250 0000 0001 2300 695","GB29 NWBK 6016 1331 9268 19",
"GR16 0110 1250 0000 0001 2300 695","GB29 NWBK 6016 1331 9268 19",
Line 5,344: Line 5,344:
...
...
"CH9300762011623852957").split()
"CH9300762011623852957").split()
.apply(validateIBAN).toString(*).println();</lang>
.apply(validateIBAN).toString(*).println();</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 5,360: Line 5,360:
=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==
{{trans|BBC BASIC}}
{{trans|BBC BASIC}}
<lang zxbasic>10 REM REM Used the following as official standard:
<syntaxhighlight lang="zxbasic">10 REM REM Used the following as official standard:
20 REM REM http://www.cnb.cz/cs/platebni_styk/iban/download/EBS204.pdf
20 REM REM http://www.cnb.cz/cs/platebni_styk/iban/download/EBS204.pdf
30 REM REM Pairs of ISO 3166 country code & expected IBAN length for this country
30 REM REM Pairs of ISO 3166 country code & expected IBAN length for this country
Line 5,423: Line 5,423:
4050 NEXT i
4050 NEXT i
4060 RETURN
4060 RETURN
5000 DEF FN m(a,b)=a-INT (a/b)*b: REM modulo</lang>
5000 DEF FN m(a,b)=a-INT (a/b)*b: REM modulo</syntaxhighlight>