Code Monkey home page Code Monkey logo

iban4j's Introduction

iban4j

Build Status Coverage Status Maven Central License

A Java library for generation and validation of the International Bank Account Numbers (IBAN ISO_13616) and Business Identifier Codes (BIC ISO_9362).

Iban quick examples:

 // How to generate Iban
 Iban iban = new Iban.Builder()
                .countryCode(CountryCode.AT)
                .bankCode("19043")
                .accountNumber("00234573201")
                .build();


 // How to create Iban object from String
 Iban iban = Iban.valueOf("DE89370400440532013000");

 // How to create Iban object from formatted String
 Iban iban = Iban.valueOf("DE89 3704 0044 0532 0130 00", IbanFormat.Default);

 // How to generate random Iban
 Iban iban = Iban.random(CountryCode.AT);
 Iban iban = Iban.random();
 Iban iban = new Iban.Builder()
                 .countryCode(CountryCode.AT)
                 .bankCode("19043")
                 .buildRandom();

 // How to validate Iban 
 try {
     IbanUtil.validate("AT611904300234573201");
     IbanUtil.validate("DE89 3704 0044 0532 0130 00", IbanFormat.Default);
     // valid
 } catch (IbanFormatException |
          InvalidCheckDigitException |
          UnsupportedCountryException e) {
     // invalid
 }

Bic quick examples:

 //How to create Bic object from String
 Bic bic = Bic.valueOf("DEUTDEFF");


         //How to validate Bic
         try{
         BicUtil.validate("DEUTDEFF500");
         // valid
         }catch(BicFormatException e){
         // invalid
         }

Enable left padding examples:

 //How to left pad('account number', 'bank code' and 'branch code') with zero
 Iban iban1=new Iban.Builder()
         .leftPadding(true)
         .countryCode(CountryCode.DE)
         .bankCode("66280099")
         .accountNumber("123456700")
         .build();

 //How to change default padding character ('0') with other
 Iban iban2=new Iban.Builder()
         .leftPadding(true)
         .paddingCharacter('1')
         .countryCode(CountryCode.DE)
         .bankCode("66280099")
         .accountNumber("123456700")
         .build();

Maven dependency:

<dependency>
    <groupId>org.iban4j</groupId>
    <artifactId>iban4j</artifactId>
  <version>3.2.9-RELEASE</version>
</dependency>

Compatibility Badge

References

License

Copyright 2015 Artur Mkrtchyan.

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

iban4j's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iban4j's Issues

Make Iban class serializable

In the age of quick access and caching Iban class should be serializable to make it easy to create a representation in Redis or other caching layers.

CH IBAN error

Hi,
String iban = "CH3200767000R53165660";
IbanUtil.validate(iban);

return false but it has to be true.

Thanks.

Provide meaningful exception messages

This code:

Iban build = new Iban.Builder()
        .countryCode(CountryCode.PL)
        .bankCode("22876")
        .accountNumber("63810519014")
        .build();
    System.out.println(build);

throws following exception:

Exception in thread "main" org.iban4j.IbanFormatException: [76nu] must contain only digits.
	at org.iban4j.IbanUtil.validateBbanEntryCharacterType(IbanUtil.java:409)
	at org.iban4j.IbanUtil.validateBbanEntries(IbanUtil.java:379)
	at org.iban4j.IbanUtil.validate(IbanUtil.java:80)
	at org.iban4j.Iban$Builder.build(Iban.java:365)
	at org.iban4j.Iban$Builder.build(Iban.java:337)

And what is even more weird, this code:

    Iban randomIban = Iban.random(CountryCode.PL);
    Iban build = new Iban.Builder()
        .countryCode(CountryCode.PL)
        .bankCode(randomIban.getBankCode())
        .accountNumber(randomIban.getAccountNumber())
        .build();

throws following exception:

Exception in thread "main" org.iban4j.IbanFormatException: [270nullnull2789991694524099] length is 27, expected BBAN length is: 24
	at org.iban4j.IbanUtil.validateBbanLength(IbanUtil.java:362)
	at org.iban4j.IbanUtil.validate(IbanUtil.java:79)
	at org.iban4j.Iban$Builder.build(Iban.java:365)
	at org.iban4j.Iban$Builder.build(Iban.java:337)

what's wrong?

Add support for Partial IBAN Countries

Currently library works straight according to ISO spec., but there is a list of countries with partially support IBAN system and have valid IBAN codes. More over many banks (like RBC etc.) work with such countries.

For more info about this countries please refer to https://www.iban.com/structure.html
I expect to have such support in this nice library.

Added New Country of JORDAN

Hi,
Added a New Country of JORDAN.

Sample: JOkk bbbb nnnn 0000 0000 cccc cccc cc
String iban = "JOXXXXXXXXXX";
IbanUtil.validate(iban);

return false but it has to be true.

Thanks.

i18n of error messages

Hi,
I have created a fork in order to be able to localize the error message for an Android client.
https://github.com/mikegr/iban4j/tree/iban4android
My fork uses the Android string resource directly. I would like to enhance iban4j so that it can both be used for Java !and! Android development. Maybe we can refactor the exception to consist of an error code and error parameters, which are later translated to ResourceBundle+MessageFormat in Java and Context.getString in Android.

Any comments on that?

Add Support for Spaces in IBAN

In Germany (and maybe other Countrys too) it is normal to format IBANs as such:

DE68 2105 0170 0012 3456 78

(Every 4 symbols comes a Whitespace)
This should be considered valid by the Validator.

IBANs with incorrect whitespace could still be marked as invalid, so a replace(" ","") can't handle it :(.
i.e.
DE6 821 050 170 001 234 567 8
DE68 21050170 0012 3456 78

Padding bank & account

Hi,

Is there any specific reason why you do not apply any zero padding in the IbanBuilder?
-> https://github.com/arturmkrtchyan/iban4j/blob/master/src/main/java/org/iban4j/Iban.java#L401 iterates all bban entries which have length information so if a certain value (bank or account number specifically) doesn't have the length as given in the bban entry zero padding could be applied.

Similarly the padding could be removed in IbanUtil#extractBbanEntry() (https://github.com/arturmkrtchyan/iban4j/blob/master/src/main/java/org/iban4j/IbanUtil.java#L452)

If you don't mind I would like to add such functionality, but if you have any reason against this please let me know.

Thanks

Builder fails for cz accounts

new Iban.Builder().countryCode(CountryCode.CZ).bankCode("2010").accountNumber("2300121591").build().toString();
should be smart enough to work without leading zeroes for accountNumber

fails with
org.iban4j.IbanFormatException: [20102300121591] length is 14, expected BBAN length is: 20 at org.iban4j.IbanUtil.validateBbanLength(IbanUtil.java:362) at org.iban4j.IbanUtil.validate(IbanUtil.java:79) at org.iban4j.Iban$Builder.build(Iban.java:365) at org.iban4j.Iban$Builder.build(Iban.java:337)

Validate Spanish national check digits in IBANs

Currently iban4j doesn't check whether or not the national check digits for Spanish IBANs are calculated correctly. For example, the following two IBANs for the same bank account pass all the checks in iban4j:

ES7021000418450200051322
ES7821000418480200051322

The IBAN checker on https://www.iban.com does not validate the first one, giving the message "Account Number checksum is invalid". The latter passes the test, as "48" is indeed the correct checksum.

Here's a set of tests that in an ideal world should all pass (only the first one does). Are there any plans to add support for verifying that the national check digits are correct?

    public class SpanishIbanTest {
        @Rule
        public ExpectedException expectedException = ExpectedException.none();

        @Test
        public void validSpanishIbanIsValidated() {
            // Validates according to www.iban.com
            IbanUtil.validate("ES7021000418450200051322", IbanFormat.None);
        }

        @Test
        public void invalidSpanishIbanIsNotValidated() {
            // DOES NOT VALIDATE according to www.iban.com
            // The national check digits should be 48, not 45
            expectedException.expectMessage("Exception");
            IbanUtil.validate("ES7821000418480200051322", IbanFormat.None);
        }

        @Test
        public void buildRandomSpanishIban() {
            Iban spanishIban = new Iban.Builder()
                    .countryCode(CountryCode.ES)
                    .bankCode("2100")
                    .branchCode("0418")
                    .accountNumber("0200051322")
                    //.nationalCheckDigit("48")
                    .buildRandom();
            assertThat(spanishIban.getNationalCheckDigit(), is("48"));
        }
    }

Checked exceptions

Right now all IBAN format exceptions are runtime exceptions. Yet the client code is actively constructing and validating ibans, it can be reasonably expected to recover from iban formatting problems.

"Runtime exceptions represent problems that are the result of a programming problem, and as such, the API client code cannot reasonably be expected to recover from them or to handle them in any way." from -http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html

Update Costa Rica BBAN Format ISO 13616 Release 78

Hi,
Can you do the update for the new Costa Rica BBAN Format.
The entry for Costa Rica is now:
CR2!n4!n14!n (length 22)
In the previous version it was shown as:
CR2!n3!n14!n (length 21)

So update needed :
BbanStructure.java
structures.put(CountryCode.CR,
new BbanStructure(
BbanStructureEntry.bankCode(4, 'n'),
BbanStructureEntry.accountNumber(14, 'n')));

HU build fails

BBAN, example for the internally used format: "11773016-11111018-00000000"

  • first 3 digits bank code.
  • next 4 branch code.
  • the 8th digit is control digit
  • from 9 to 16 or 24 is bank account.
  • the 16th or 24th digit is control digit

By debugging I see that the following builders are considered at HU:
String bankCode = "117";
String branchCode = "7301";
String nationalCheckDigit = "6";
String accountNumber = "1111101800000000";
Iban iban = new Iban.Builder()
.countryCode(CountryCode.HU)
.bankCode(bankCode)
.branchCode(branchCode)
.nationalCheckDigit(nationalCheckDigit)
.accountNumber(accountNumber)
.build();
Now this returns the iban number:
HU58117730111111018000000006
But correct generators, also online generators from "11773016-11111018-00000000" will build
HU??117730161111101800000000
So in iban4j the 8th BBAN character, the nationalCheckDigit gets appended to the end, that's why still the IBAN length is right. The nationalCheckDigit is not to be positioned as the last digit. It is the 8th digit in the BBAN format.

Dutch IBAN does not validate

A special class of Dutch IBAN numbers fails to validate.

Number in question: NL19INGB0005154161

The history about this type of numbers is that it is a really old Dutch bank account, that got subsequently upgraded to the nowadays standard of Dutch account numbers and then got upgraded to an IBAN number.

Possibly different rules apply to this number, I'll try to get more information on this.

http://www.tuxx.nl/betalingsverkeer/iban_controle_module/ validates it as a correct IBAN number.

Working random IBAN generation for France

For French IBANs, there can be different consistency checks

  • Existing BankCode
  • Existing BrancheCode
  • Consistency of FR nationalCheckDigit

So random generated IBANs with Country.FR are not valid.

Here is a workaround for anyone looking for it ( maybe you can integrate it in your library if you like )

      String bankCode = "30006" ;
      String branchCode = "00001" ;
      Random r = new Random();
      int Low = 10;
      int High = 1000000;
      int AccountNumberInt = r.nextInt(High-Low) + Low;
      String AccountNumberStr = String.valueOf(AccountNumberInt);
      String AccountNumber = StringUtils.repeat("0", 11 - AccountNumberStr.length()) + AccountNumberStr;
      long a100000000000 =  (long) 100000000000.0;
      Long nationalCheckDigitInt = 97 - (((Long.valueOf(bankCode) % 97 * 100000 + Integer.valueOf(branchCode)) % 97 * a100000000000 + Integer.valueOf(AccountNumber)) % 97) * 100 % 97;
       String nationalCheckDigit = String.valueOf(nationalCheckDigitInt) ;
       Iban iban = new Iban.Builder().countryCode(CountryCode.FR).bankCode(bankCode).branchCode(branchCode).accountNumber(AccountNumber).nationalCheckDigit(nationalCheckDigit).buildRandom();  

Vatican Iban

Library return an error with Vatican iban.
Country Code "VA" is not present in BbanStructure.

Add support for SWIFT codes

Hey there. Adding SWIFT validation support would be a decent complementation to this fine, light library.

Added 3 new iban countries.

Hi,
Added 3 new iban countries.
Can you help me?

We have added IBAN validation support for three new countries which have partial IBAN coverage.
The new supported countries are :
El Salvador ( SV )
Honduras ( HN )
Nicaragua ( NI )
Here are some test cases for those countries:

SV43ACAT00000000000000123123
HN54PISA00000000000000123124
NI92BAMC000000000000000003123123

thanks.

Hi

Hi,
String iban = "BG07BINV94801402174800";
IbanUtil.validate(iban);

return false but it has to be true.

Thanks.

Find BIC from IBAN

Add support for finding a BIC (and bank related information) from an IBAN.

How to handle IBANs which country codes are not supported by BbanStructure

Hi, BbanStructure structure contains description of about 65 IBANs by their country code. But how to handle IBANs for other countries?

  • Is there a reason why not all of them are listed?
  • Is it possible to add missing descriptions?
  • Is it possible to handle such IBAN a different way using this library?

My current problem comes from Greenland: GL8964710001000206

Thank you in advance for any hint!

Gives incorrect result? Please advise

I'm trying with Hungarian bank accounts. This is a Hungarian bank account format:

11600006-00000000-34953226

This is how it looks:

116 is the bank code
0000 is the branch code
6 is the national digit
0000000034953226 is the account number (16 long)

According to the converter here:
https://www.iban.com/calculate-iban

This is the IBAN number for that account:
HU74116000060000000034953226

So putting this into code:

Iban iban = Iban.valueOf("HU74116000060000000034953226");
Iban.Builder builder = new Iban.Builder();
System.out.println(iban.getNationalCheckDigit()); //gives 6, correct
builder.nationalCheckDigit(iban.getNationalCheckDigit());
System.out.println(iban.getCountryCode()); //gives HU, correct
builder.countryCode(iban.getCountryCode());
System.out.println(iban.getAccountNumber()); //gives 6000000003495322, incorrect
builder.accountNumber(iban.getAccountNumber());
System.out.println(iban.getBankCode());
builder.bankCode(iban.getBankCode()); //gives 116, correct
System.out.println(iban.getBranchCode());
builder.branchCode(iban.getBranchCode()); //gives 0000, correct
Iban iban2 = builder.build(true);
System.out.println(iban2.toString()); //gives HU74116000060000000034953226, correct

So this gives me the same IBAN:

Iban iban = new Iban.Builder()
.bankCode("116")
.branchCode("0000")
.nationalCheckDigit("6")
.accountNumber("6000000003495322")
.countryCode(CountryCode.HU)
.build(true);
System.out.println("IBAN: "+iban.toString());

However, with the correct account number:

Iban iban = new Iban.Builder()
.bankCode("116")
.branchCode("0000")
.nationalCheckDigit("6")
.accountNumber("0000000034953226")
.countryCode(CountryCode.HU)
.build(true);
System.out.println("IBAN: "+iban.toString());

I get a totally different IBAN number: HU36116000000000000349532266

This is presented as "valid", but this is an incorrect number.

Looks like the numbers inside the account number are shifted in some way?

Romania IBAN

Hi Arthur,
incorrect IBAN
Example: RO91BRDE360SV54748603600

Add support for Java 9 Modules

Add a module-info.java file to the library so that it is compatible with Java 9+. Specifically, doing so will avoid the following warning when including Iban4J in a Java 9 project:

[WARNING] ********************************************************************************************************************
[WARNING] * Required filename-based automodules detected. Please don't publish this project to a public artifact repository! *
[WARNING] ********************************************************************************************************************

validate bic with iban

Character 5 and 6 of a BIC needs to be equal with the country code from IBAN.
IBAN DE89370400440532013000. BIC DEUTDEFF500

When these characters doesn't match, you can say that the IBAN has a wrong BIC.

Is it possible to add a validation method to look if an IBAN has a valid BIC (or visa versa) with the right error handling?

Thx!

Wrong Bank code structure for Virgin Islands

BbanStructure states that it is 4c, where as according to Registration Authority for ISO 13616 Release 69 โ€“ August 2016 it is 4a. Not a single IBAN validator consumes alphanumerical Bbans for VG.

cant convert bban to iban because bban for Norway is appended with "null" which increases its length and validation is failing

BBAN for Norway is appended with "null" which increases its length and hence validation is failing. Can you help me if i'm missing something? Or can this issue be fixed?

I feel its messed up in "iban.java" under method "formatIban()" when converting "toString" in the end.

        private String formatIban() {
            final StringBuilder sb = new StringBuilder();
            sb.append(countryCode.getAlpha2());
            sb.append(DEFAULT_CHECK_DIGIT);
            sb.append(formatBban());
            return sb.toString();
        }

Test Data BBAN: 44350343730
Code used:

String set = "44350343730";
String bankCode = "4435";
String account = "0343730";

Iban.Builder builder = new Iban.Builder();
builder.countryCode(CountryCode.NO);
builder.bankCode(bankCode);
builder.accountNumber(account);

Iban value = builder.build();

Error thrown:

Exception in thread "main" org.iban4j.IbanFormatException: [44350343730null] length is 15, expected BBAN length is: 11
	at org.iban4j.IbanUtil.validateBbanLength(IbanUtil.java:362)
	at org.iban4j.IbanUtil.validate(IbanUtil.java:79)
	at org.iban4j.Iban$Builder.build(Iban.java:365)
	at org.iban4j.Iban$Builder.build(Iban.java:337)

Error with UK sort and account code

Iban iban = new Iban.Builder()
.countryCode(CountryCode.GB)
.bankCode("090136")
.accountNumber("99736889")
.build();

org.iban4j.IbanFormatException: [0901] must contain only upper case letters.
at org.iban4j.IbanUtil.validateBbanEntryCharacterType(IbanUtil.java:391)
at org.iban4j.IbanUtil.validateBbanEntries(IbanUtil.java:379)
at org.iban4j.IbanUtil.validate(IbanUtil.java:80)
at org.iban4j.Iban$Builder.build(Iban.java:365)
at org.iban4j.Iban$Builder.build(Iban.java:337)

Ibans ending in CREDIT

I'm working on processing transaction statements and I'm finding IBANS of the format BE59[digits omitted for privacy]CREDIT.

This isn't part of the IBAN spec right?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.