Class IBAN

java.lang.Object
nl.garvelink.iban.IBAN
All Implemented Interfaces:
Serializable

public final class IBAN extends Object implements Serializable
An immutable value type representing an International Bank Account Number. Instances of this class have correct check digits and a valid length for their country code. No country-specific validation is performed, other than matching the length of the IBAN to its country code. Unknown country codes are not supported.
Author:
Barend Garvelink https://github.com/barend
See Also:
  • Field Details

  • Method Details

    • parse

      public static IBAN parse(CharSequence input)
      Parses the given string into an IBAN object and confirms the check digits.
      Parameters:
      input - the input, which can be either plain ("CC11ABCD123...") or formatted with (ASCII 0x20) space characters ("CC11 ABCD 123. ..").
      Returns:
      the parsed and validated IBAN object, never null.
      Throws:
      IllegalArgumentException - if the input is null, malformed or otherwise fails validation.
      See Also:
    • valueOf

      public static IBAN valueOf(CharSequence input)
      Parses the given string into an IBAN object and confirms the check digits, but returns null for null.
      Parameters:
      input - the input, which can be either plain ("CC11ABCD123...") or formatted ("CC11 ABCD 123. ..").
      Returns:
      the parsed and validated IBAN object, or null.
      Throws:
      IllegalArgumentException - if the input is malformed or otherwise fails validation.
      See Also:
    • compose

      public static IBAN compose(CharSequence countryCode, CharSequence bban)
      Composes an IBAN from the given country code and basic bank account number.
      Parameters:
      countryCode - the country code.
      bban - the BBAN.
      Returns:
      an IBAN object composed from the given parts, if valid.
      Throws:
      IllegalArgumentException - if either input is null, if the composed IBAN fails validation.
      Since:
      1.9.0
    • getLengthForCountryCode

      @Deprecated public static int getLengthForCountryCode(String countryCode)
      Parameters:
      countryCode - the country code for which to return the length.
      Returns:
      the length of the IBAN for the given country code, or -1 if unknown.
    • getCountryCode

      public String getCountryCode()
      Returns the Country Code embedded in the IBAN.
      Returns:
      the two-letter country code.
    • getCheckDigits

      public String getCheckDigits()
      Returns the check digits of the IBAN.
      Returns:
      the two check digits.
    • isSEPA

      public boolean isSEPA()
      Returns whether the IBAN's country participates in SEPA.
      Returns:
      true if SEPA, false if non-SEPA.
    • isInSwiftRegistry

      public boolean isInSwiftRegistry()
      Returns whether the source for this IBAN's format and data is the SWIFT IBAN Registry.
      Returns:
      true if from SWIFT IBAN Registry, false if from Experimental IBANs list.
      Since:
      1.6.0
    • toPlainString

      public String toPlainString()
      Returns the IBAN without formatting.
      Returns:
      the unformatted IBAN number.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns the IBAN in standard formatting, with a space every four characters.
      Overrides:
      toString in class Object
      Returns:
      the formatted IBAN number.
      See Also:
    • toPlain

      public static String toPlain(CharSequence input)
      Removes any spaces contained in the String thereby converting the input into a plain IBAN
      Parameters:
      input - possibly pretty printed IBAN
      Returns:
      plain IBAN
    • toPretty

      public static String toPretty(CharSequence input)
      Ensures that the input is pretty printed by first removing any spaces the String might contain and then adding spaces in the right places.

      This can be useful when prompting a user to correct wrong input

      Parameters:
      input - plain or pretty printed IBAN
      Returns:
      pretty printed IBAN