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.
Except the national check digit, which is pretty common, the following information were considered too specific to be part of the jbanking API :
- account type (Bulgaria, Brasil, Guatemala),
- account currency (Guatemala, Mauritius, Seychelles),
- balance account number (Belarus),
- identification number (Iceland),
- owner account number (Brasil),
- reserved characters (Costa Rica, Mauritius).
This class handles validation of the check digit and validation of the BBAN structure.
Instances of this class are immutable and thread-safe.
This class implements Serializable for convenience, but you are encouraged to use the normalized string representation if possible. Note that no validity check is done during deserialization.
Usage:
// Validate an IBAN
Assertions.assertTrue(Iban.isValid(" fr2531682128768051490609537 "));
// Get IBAN information
Iban iban = new Iban(" fr2531682128768051490609537 ");
Assertions.assertEquals("FR2531682128768051490609537", iban.toString());
Assertions.assertEquals("FR25 3168 2128 7680 5149 0609 537", iban.toPrintableString());
Assertions.assertEquals("FR", iban.getCountryCode());
Assertions.assertEquals("25", iban.getCheckDigit());
Assertions.assertEquals("31682128768051490609537", iban.getBban());
Assertions.assertEquals("31682", iban.getBankIdentifier());
Assertions.assertEquals("12876", iban.getBranchIdentifier().get());
Assertions.assertEquals("80514906095", iban.getAccountNumber());
Assertions.assertEquals("37", iban.getNationalCheckDigit().get());
-
Field Summary
Fields -
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 TypeMethodDescriptionbooleanExtract the national account number from this IBAN.Extract the bank identifier (also known as bank code) from this IBAN.getBban()Extract the BBAN from this IBAN.Extract the branch identifier (also known as branch code) from this IBAN, if possible.Extract the check digit from this IBAN.Gets this IBANIsoCountry.Extract the ISO 3166-1-alpha-2 country code from this IBAN.Extract the national check digit (also known as check character) from this IBAN, if possible.inthashCode()static booleanValidates the given IBAN String.Gets the printable version of this IBAN.toString()Returns a normalized string representation of this IBAN.
-
Field Details
-
REGEX
A simple regex that validate well-formed IBANs.All strings accepted by
isValid(String)are also accepted by this regex.- See Also:
-
-
Constructor Details
-
Iban
Create a new IBAN from the given country code and BBAN.This method is neither sensitive to the case nor to the presence of leading or trailing spaces.
- Parameters:
country- a non-null IsoCountrybban- 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.This method is neither sensitive to the case nor to the presence of leading or trailing spaces.
- Parameters:
s- 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.This method is neither sensitive to the case nor to the presence of leading or trailing spaces.
- Parameters:
s- a string, may benull- 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
-
getCountry
Gets this IBANIsoCountry.- Returns:
- a non-null
IsoCountry
-
getCheckDigit
Extract the check digit from this IBAN.- Returns:
- a non-null string
-
getBban
Extract the BBAN from this IBAN.- Returns:
- a non-null string
-
getBankIdentifier
Extract the bank identifier (also known as bank code) from this IBAN.- Returns:
- a non-null string
- Since:
- 4.0.0
-
getBranchIdentifier
Extract the branch identifier (also known as branch code) from this IBAN, if possible.- Returns:
- a non-null optional string
- Since:
- 4.0.0
-
getNationalCheckDigit
Extract the national check digit (also known as check character) from this IBAN, if possible.The type of the check digit and the algorithm used to compute it varies by country (RIB key in France, CIN in Italy...).
- Returns:
- a non-null optional string
- Since:
- 4.0.0
-
getAccountNumber
Extract the national account number from this IBAN.- Returns:
- a non-null string representing this IBAN account number
- Since:
- 4.0.0
-
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
Returns a normalized string representation of this IBAN.Normalized means the string is:
- made of uppercase characters
- contains no spaces
-
equals
-
hashCode
public int hashCode()
-