Class Iban
- All Implemented Interfaces:
Serializable
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 Summary
ConstructorsConstructorDescriptionIban(IsoCountry country, String bban) Create a new IBAN from the given country code and BBAN.Create a new IBAN from the given string. -
Method Summary
Modifier and TypeMethodDescriptionbooleangetBban()Extract the BBAN from this IBAN.Extract the check digit from this IBAN.Extract the ISO 3166-1-alpha-2 country code from this IBAN.inthashCode()Returns a normalized string representation of this IBAN.static booleanValidates the given IBAN String.Gets the printable version of this IBAN.toString()
-
Constructor Details
-
Iban
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 isnullIbanFormatException- if a valid IBAN could not be calculated using the given IsoCountry and BBAN.
-
Iban
Create a new IBAN from the given string.- Parameters:
iban- A non-null String.- Throws:
IllegalArgumentException- if the given string isnullIbanFormatException- if the given string is not a valid IBAN.
-
-
Method Details
-
isValid
Validates the given IBAN String.- Parameters:
iban- A String.- Returns:
trueif the given String is a valid IBAN,falseotherwise.
-
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
Extract the check digit from this IBAN.- Returns:
- A non-null string representing this IBAN check digit.
-
getBban
Extract the BBAN from this IBAN.- Returns:
- A non-null string representing this IBAN BBAN.
-
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
-
equals
-
hashCode
public int hashCode()Returns a normalized string representation of this IBAN.Normalized means the string is:
- made of uppercase characters
- contains no spaces
-