Jump to content

IBAN: Difference between revisions

2,527 bytes added ,  5 years ago
no edit summary
m (cleaner gawk invocation)
No edit summary
Line 2,269:
return mod==1
end</lang>
 
=={{header|M2000 Interpreter}}==
We make a lambda function which return a string, with the input IBAN plus (Valid) or (Invalid) at the end.
 
<lang M2000 Interpreter>
\\ IBAN checker
Function MakeIBANfun$ {
Inventory countrylength = "AL" := 28, "AD" := 24, "AT" := 20, "AZ" := 28, "BE" := 16, "BH" := 22, "BA" := 20, "BR" := 29
Append countrylength, "BG" := 22, "CR" := 21, "HR" := 21, "CY" := 28, "CZ" := 24, "DK" := 18, "DO" := 28, "EE" := 20
Append countrylength, "FO" := 18, "FI" := 18, "FR" := 27, "GE" := 22, "DE" := 22, "GI" := 23, "GR" := 27, "GL" := 18
Append countrylength, "GT" := 28, "HU" := 28, "IS" := 26, "IE" := 22, "IL" := 23, "IT" := 27, "KZ" := 20, "KW" := 30
Append countrylength, "LV" := 21, "LB" := 28, "LI" := 21, "LT" := 20, "LU" := 20, "MK" := 19, "MT" := 31, "MR" := 27
Append countrylength, "MU" := 30, "MC" := 27, "MD" := 24, "ME" := 22, "NL" := 18, "NO" := 15, "PK" := 24, "PS" := 29
Append countrylength, "PL" := 28, "PT" := 25, "RO" := 24, "SM" := 27, "SA" := 24, "RS" := 22, "SK" := 24, "SI" := 19
Append countrylength, "ES" := 24, "SE" := 24, "CH" := 21, "TN" := 24, "TR" := 26, "AE" := 23, "GB" := 22, "VG" := 24
=Lambda$ countrylength (Iban0$)->{
Iban$=Filter$(Ucase$(Iban0$), " ")
Iban$=Filter$(Iban$, Filter$(Iban$,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))
Def Decimal ch, c
{
If Not Exist(countrylength, Left$(Iban$,2)) Then Exit
length=Eval(countrylength)
If Not Len(Iban$)=length Then exit
Buffer ScanChar as Integer*length
Return ScanChar, 0:=Mid$(Iban$,5), length-4:=Mid$(Iban$,1,4)
For i=0 to length-1 {
ch=Eval(ScanChar, i)
if ch>=48 and ch<=57 then {
c = c*10+ch-48
} else.if ch>=65 and ch<=90 then {
c = c*100+ch-55
} else c=-1: exit
c = c mod 97
}
}
=Iban0$ + If$(c=1 ->" (Valid)", " (Invalid)")
}
}
IbanCheck$=MakeIBANfun$()
Print IbanCheck$("GB82 WEST 1234 5698 7654 32") ' valid
Print IbanCheck$("GB82 TEST 1234 5698 7654 32")
Print IbanCheck$("SA03 8000 0000 6080 1016 7519") ' valid
Print IbanCheck$("GR16 0110 1250 0000 0001 2300 695X")
Print IbanCheck$("MK11 2222 3333 4444 555")
</lang>
 
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.