Class Iban

java.lang.Object
fr.marcwrobel.jbanking.iban.Iban
All Implemented Interfaces:
Serializable

public final class Iban extends Object implements Serializable
An International Bank Account Number (IBAN) Code as specified by the ISO 13616:2007 standard.

An IBAN consists of a two-letter ISO 3166-1 country code, followed by two check digits and up to thirty alphanumeric characters for a BBAN (Basic Bank Account Number) which has a fixed length per country and, included within it, a bank identifier with a fixed position and a fixed length per country. The check digits are calculated based on the scheme defined in ISO/IEC 7064 (MOD97-10). Note that an IBAN is case-insensitive.

This class handles validation of the check digit and validation of the BBAN structure.

Instances of this class are immutable and thread-safe.

Usage:

 // Validate an IBAN
 Assertions.assertTrue(Iban.isValid("FR2531682128768051490609537"));

 // Retrieve IBAN information
 Iban iban = new Iban("fr2531682128768051490609537");
 Assertions.assertEquals("FR2531682128768051490609537", iban.toString());
 Assertions.assertEquals("FR", iban.getCountryCode());
 Assertions.assertEquals("25", iban.getCheckDigit());
 Assertions.assertEquals("31682128768051490609537", iban.getBban());
 Assertions.assertEquals("FR25 3168 2128 7680 5149 0609 537", iban.toPrintableString());
 
Since:
1.0
See Also:
  • Constructor Details

    • Iban

      public Iban(IsoCountry country, String bban)
      Create a new IBAN from the given country code and BBAN.
      Parameters:
      country - A non-null IsoCountry.
      bban - A non-null String.
      Throws:
      IllegalArgumentException - if either the IsoCountry or BBAN is null
      IbanFormatException - if a valid IBAN could not be calculated using the given IsoCountry and BBAN.
    • Iban

      public Iban(String iban)
      Create a new IBAN from the given string.
      Parameters:
      iban - A non-null String.
      Throws:
      IllegalArgumentException - if the given string is null
      IbanFormatException - if the given string is not a valid IBAN.
  • Method Details

    • isValid

      public static boolean isValid(String iban)
      Validates the given IBAN String.
      Parameters:
      iban - A String.
      Returns:
      true if the given String is a valid IBAN, false otherwise.
    • getCountryCode

      public String getCountryCode()
      Extract the ISO 3166-1-alpha-2 country code from this IBAN.
      Returns:
      A non-null string representing this IBAN ISO 3166-1-alpha-2 country code.
    • getCheckDigit

      public String getCheckDigit()
      Extract the check digit from this IBAN.
      Returns:
      A non-null string representing this IBAN check digit.
    • getBban

      public String getBban()
      Extract the BBAN from this IBAN.
      Returns:
      A non-null string representing this IBAN BBAN.
    • toPrintableString

      public String toPrintableString()
      Gets the printable version of this IBAN.

      When printed on paper, the IBAN is expressed in groups of four characters separated by a single space, the last group being of variable length

      Returns:
      A non-null string representing this IBAN formatted for printing.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Returns a normalized string representation of this IBAN.

      Normalized means the string is:

      • made of uppercase characters
      • contains no spaces
      Overrides:
      hashCode in class Object
      Returns:
      a normalized string representation of this IBAN