IBAN: Difference between revisions

11 bytes added ,  11 years ago
m
Minor edit
(added Caché ObjectScript)
 
m (Minor edit)
Line 1:
{{draft task}}
{{wikipedia}}
The [[wp:International_Bank_Account_Number|International Bank Account Number (IBAN)]] is an internationally agreed means of identifying bank accounts across national borders with a reduced risk of propagating [[wp:Transcription_error|transcription errors]]. The IBAN consists of up to 34 alphanumeric characters: first the two-letter ISO 3166-1 alpha-2 country code, then two check digits, and finally a country-specific Basic Bank Account Number (BBAN). The check digits enable a sanity check of the bank account number to confirm its integrity even before submitting a transaction.
 
The task here is to validate the following fictitious IBAN: GB82 WEST 1234 5698 7654 32. Details of the algorithm can be found on the Wikipedia page.
Line 10:
{
 
ClassMethod IBAN(ibanpIBAN As %String = "") As %Boolean
{
If ibanpIBAN=..IBANGenerate(ibanpIBAN) Quit 1
Quit 0
}
 
ClassMethod IBANGenerate(ibanpIBAN As %String = "") As %String
{
Set ibanpIBAN=$ZConvert(ibanpIBAN, "U")
Set cc=$Extract(ibanpIBAN, 1, 2)
Set cd=$Extract(ibanpIBAN, 3, 4)
Set bban=$Extract(ibanpIBAN, 5, *)
Set str="", alt=$ZStrip(bban_cc_"00", "*E'U'N")
For i=1:1:$Length(alt) {
Line 33:
}
 
ClassMethod Mod(strnum As %StringInteger, div As %Integer) As %Integer [ Internal, Private ]
{
If $Length(strnum)<9 Quit strnum#div
Set res=0
For i=1:1:$Length(strnum)\7+1 {
Set res=(res_$Extract(strnum, 1, 7))#div
Set strnum=$Extract(strnum, 8, *)
}
Quit res