Validating and decoding an IBAN

Use BWIGetValue to validate an International Bank Account Number (IBAN). This returns 1 if the IBAN has the correct basic format and passes the IBAN modulus checking. Also, BWI_V_COUNTRY_CHECK for the handle is either set to the country or -1 if the country is not known. In this case, your application must set a country code before iterating through conditions.

When the correct country is initialised, Bank Wizard checks that the IBAN has the correct format for the country. If it does have, the IBAN is decomposed into the basic strings that make up the local account details.

For some countries, such as the UK and the Republic of Ireland, as well as the standard account details, the Bank Identifier is also returned.

BWICreateHandle(h)

BWISetString(h,BWI_V_IBAN,BE62510007547061)

/* This determines if the IBAN is valid */

BWIGetValue(h,BWI_V_IBAN,valid)

/* If GetValue returns 1, the string has the correct format and passes the IBAN modulus check. */

BWIGetValue(h,BWI_V_COUNTRY_CHECK,countryId)

if(valid) {

/* Handle's country is changed to the IBAN country, or to -1 if this country is not known */

print("IBAN appears valid. Country id = " + countryId)

} else {

print("IBAN is not valid")

}

/* If the IBAN is valid and the country is known, the error BWI_G_IBAN_FORMAT can still be set. If country available and is initialised then Bank Wizard validates the country IBAN format */

if(BWINext(h,BWI_N_ERROR) {

/* Reset iterator so can enter the While loop at the first error */

BWINext(h,BWI_N_NONE)

while(BWINext(h,BWI_N_ERROR)) {

BWIGetValue(h,BWI_V_NEXT,cond)

BWIGetString(h,BWI_V_NEXT,mess)

print(cond + " " + mess)

}

} else {

/* Is the country loaded or initialised? */

BWIGetValue(h,BWI_V_LOADED,loaded)

if(loaded) {

/* IBAN was valid and no errors, print the account details returned */

for(i = BWI_V_PAR1; i <= BWI_V_PAR5; i = i + 1) {

BWIGetString(h,i,string)

print("String " + i + " = " + string)

}

} else {

print("Country " + countryID + "is not loaded")

}

}