Class IBAN


  • public class IBAN
    extends java.lang.Object
    Utility class to validate IBAN codes.

    The IBAN consists of a ISO 3166-1 alpha-2 country code, followed by two check digits (represented by kk in the examples below), and up to thirty alphanumeric characters for the domestic bank account number, called the BBAN (Basic Bank Account Number).

    Exampe usage scenario

    IBAN iban = new IBAN("ES2153893489");
     if (iban.isValid())
         System.out.println("ok");
     else
         System.out.println("problem with iban: "+iban.getInvalidCause());
     
    Since:
    3.3
    • Constructor Summary

      Constructors 
      Constructor Description
      IBAN​(java.lang.String iban)
      Create an IBAN object with the given iban code.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getBban()
      Gets the BBAN (custom account number) part of the IBAN
      static java.lang.String getBban​(java.lang.String iban)
      Gets the BBAN (custom account number) part of the given IBAN
      java.lang.String getCheckDigits()
      Gets the check digits part of the IBAN
      static java.lang.String getCheckDigits​(java.lang.String iban)
      Gets the check digits part of the given IBAN.
      java.lang.String getCountryCode()
      Gets the country code part of the IBAN
      static java.lang.String getCountryCode​(java.lang.String iban)
      Gets the country code part of the given IBAN.
      java.lang.String getIban()
      Get the IBAN
      boolean isValid()
      Checks if the IBAN number is valid.
      java.lang.String removeNonAlpha​(java.lang.String iban)
      Removes all non alpha-numeric characters in the IBAN code
      void setIban​(java.lang.String iban)
      Set the IBAN
      java.lang.String translateChars​(java.lang.StringBuilder str)
      Translate letters to numbers, also ignoring non alphanumeric characters
      IbanValidationResult validate()
      Check an IBAN number throwing an exception with validation details if it is not valid.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IBAN

        public IBAN​(java.lang.String iban)
        Create an IBAN object with the given iban code. This constructor does not perform any validation on the iban, only
        Parameters:
        iban - the IBAN string
    • Method Detail

      • getBban

        public static java.lang.String getBban​(java.lang.String iban)
                                        throws java.lang.IndexOutOfBoundsException
        Gets the BBAN (custom account number) part of the given IBAN
        Parameters:
        iban - a well-formed IBAN
        Returns:
        the custom account part of the IBAN
        Throws:
        java.lang.IndexOutOfBoundsException - if the IBAN length is wrong
        Since:
        7.9.7
      • getCheckDigits

        public static java.lang.String getCheckDigits​(java.lang.String iban)
                                               throws java.lang.IndexOutOfBoundsException
        Gets the check digits part of the given IBAN.
        Parameters:
        iban - a well-formed IBAN
        Returns:
        the check digits (two digits as String)
        Throws:
        java.lang.IndexOutOfBoundsException - if the IBAN length is wrong
        Since:
        7.9.7
      • getCountryCode

        public static java.lang.String getCountryCode​(java.lang.String iban)
                                               throws java.lang.IndexOutOfBoundsException
        Gets the country code part of the given IBAN.
        Parameters:
        iban - a well-formed IBAN
        Returns:
        the two letters ISO country code
        Throws:
        java.lang.IndexOutOfBoundsException - if the IBAN length is wrong
        Since:
        7.9.7
      • getIban

        public java.lang.String getIban()
        Get the IBAN
        Returns:
        a string with the IBAN
      • setIban

        public void setIban​(java.lang.String iban)
        Set the IBAN
        Parameters:
        iban - the IBAN to set
      • validate

        public IbanValidationResult validate()
        Check an IBAN number throwing an exception with validation details if it is not valid.

        Validates that the length is at least 5 chars: composed by a valid 2 letters ISO country code, 2 verifying digits, and 1 BBAN. The verification digits are also computed and verified. For the BBAN validation the specific per country structure must be defined either in the BbanStructureValidations.json file or by API in the BbanStructureValidations instance.

        Non alpha-numeric characters are removed from the code prior to validation. Meaning an IBAN such as "ES64 0049 6170 68 2810279951" will be considered valid.

        Returns:
        IbanFormatStatus with detailed information of the validation problem found
      • translateChars

        public java.lang.String translateChars​(java.lang.StringBuilder str)
        Translate letters to numbers, also ignoring non alphanumeric characters
        Parameters:
        str - input string
        Returns:
        the translated value
      • removeNonAlpha

        public java.lang.String removeNonAlpha​(java.lang.String iban)
        Removes all non alpha-numeric characters in the IBAN code
        Parameters:
        iban - IBAN string
        Returns:
        the resulting IBAN
      • getBban

        public java.lang.String getBban()
        Gets the BBAN (custom account number) part of the IBAN
        Returns:
        the custom account part of the IBAN or null if the IBAN has an invalid length
        Since:
        7.9.7
      • getCheckDigits

        public java.lang.String getCheckDigits()
        Gets the check digits part of the IBAN
        Returns:
        the check digits (two digits as String) of the IBAN or null if the IBAN has an invalid length
        Since:
        7.9.7
      • getCountryCode

        public java.lang.String getCountryCode()
        Gets the country code part of the IBAN
        Returns:
        the two letters ISO country code of the IBAN or null if the IBAN has an invalid length
        Since:
        7.9.7