Java IBAN check digit validation

The International Bank Account Number (IBAN) is an international standard for identifying bank accounts across national borders. It was originally adopted by the European Committee for Banking Standards, and was later adopted as an ISO standard (ISO 13616). Although currently only used in Europe, where it was adopted to facilitate cross border payments, it is anticipated that IBAN will a more global standard in a few years.

A quick search on the web for IBAN will show up information on the standard, including some web based validators. Since I could not find one, I have just put together a Java implementation of the IBAN check digit validation algorithm based on ECBS IBAN standard v 3.2. Code , including test cases, are available here. Please note that this works with the ‘electronic format’ (no spaces) of IBAN and not the ‘paper format’.

The code is reasonably straight forward, the challenge I had was to elegantly determine the appropriate numeric value of a letter as per section 6.3 (Alpha to Numeric conversion). In the end I found the simplest way was to compare the given character to ‘A’. This gave me the position of the character in the alphabet. Two key points though:

  1. Comparison of characters must be in the same case. Don’t compare ‘D’ to ‘a’.
  2. The position will start at zero. For example, E the fifth letter in the alphabet is at position 4.

Here is the code snippet for that:


private static int getAlphabetPosition(char letter) {
return Character.valueOf(
Character.toUpperCase(letter))
.compareTo(Character.valueOf('A')
);
}

Of course once you have the position of a letter in the alphabet don’t forget to add 10 to the result to get the numeric value as per IBAN standard.

In the implementation I have included an IBAN.properties which contains the lengths for all the country codes currently signed up to the IBAN initiative. You could take this forward by adding in the formatting patterns that exist for each country and include this in the validation too.

11 thoughts on “Java IBAN check digit validation

  1. Hi.Great job!But I was wondering if you could tell me how to make it JDK 1.4.2 friendly?I’ve got problems with:- IBAN.class.getCanonicalName()- Character.valueOfThanks.

    Like

  2. The ISO has designated SWIFT to act as the registration authority for national IBAN formats. SWIFT publishes the ISO 13616 IBAN Registry. However, not every IBAN has a BIC. It is up to the ISO national standards bodies or the national central banks to define the structure of the BBAN. To my knowledge only Bulgaria, Ireland, Latvia and Malta have the BIC (or the first few characters of it) in the BBAN.

    Like

  3. Nice code.I wonder if you have come across any good BBAN number generators for Linux/perl/Java?We’re gonna convert our clients bank account numbers to IBAN so we then can do (more or less) automatic bulk payments with our bank instead of manual labour.There’s a lot of BBAN->IBAN converters out there but I have’nt found any which can convert raw account info to BBAN. I guess it’s proprietary to the bank and country but someone must have stumbled across the same issue if not the banks themselves. Any PSP must handle this issue I guess right?

    Like

  4. Marcus,The BBAN structure is different in almost every country. Conveniently, this structure is listed in the IBAN registry. Each bank needs to determine for themselves how their accounts are uniquely identified. The BBAN will have the bank identifier and this ‘unique key’ value. The ‘unique key’ may have to be padded or truncated to fit the BBAN length. You would need to check with the bank what approach they have planned for uniquely identifying their accounts.Peter

    Like

  5. Hi Peter,I was testing one application where I need to enter the BBAN number for a particular bank but after many trials and error i was able to enter a correct BBAN. Is there any method or the generator available which can generate the BBAN for a country.Thanks a lot for your help in advance.Best Regards

    Like

  6. The BBAN structure is different in almost every country. Conveniently, this structure is listed in the IBAN registry. So, you could write your own generator based on that. Each bank needs to determine for themselves how their accounts are uniquely identified. The BBAN will have the bank identifier and this ‘unique key’ value. The ‘unique key’ may have to be padded or truncated to fit the BBAN length. So, even if you know the countries BBAN format, you would need to check with the bank what approach they have planned for uniquely identifying their accounts. This is generally why there are no BBAN generators available.

    Like

  7. Good fill someone in on and this mail helped me alot in my college assignement. Gratefulness you as your information.

    Like

Leave a comment