Skip to content
Pololei
Documentation / BBAN fields

BBAN fields and the account number

Decision: accountNumber() keeps its meaning, the national fields are added

Status: decided for the next minor release; no incompatible change.

Iban.accountNumber() returns, as documented since the first release, all BBAN characters outside the bank and branch identifier of the SWIFT IBAN registry. For several countries that is more than the account number in the national sense, because the registry does not describe national check digits, account types or, for France, the branch code:

IBANaccountNumber()national account number
IT60X0542811101000000123456X000000123456 (CIN + account)000000123456
ES9121000418450200051332450200051332 (check digits + account)0200051332
FR1420041010050500013M02606010050500013M02606 (branch + account + RIB key)0500013M026

Changing accountNumber() would silently change the results of existing callers. Instead pololei adds an unambiguous, additive API:

  • Iban.field(BbanField) and Iban.fields() read the national fields;
  • IbanBuilder.field(BbanField, String) sets them; bankIdentifier(...) and branchIdentifier(...) are shortcuts for the two identifier fields;
  • IbanCountry.bbanLayout() describes position and length of every field;
  • Bban.validateField(...) validates a single field.

Getter and builder input belong together and mean the same:

ReadWriteMeaning
iban.accountNumber()builder.accountNumber(...)everything outside the registry's bank and branch identifier
iban.field(ACCOUNT_NUMBER)builder.field(ACCOUNT_NUMBER, ...)the national account number
iban.field(NATIONAL_CHECK_DIGITS)builder.field(NATIONAL_CHECK_DIGITS, ...) or nationalCheckDigits(true)national check digits, given or calculated

accountNumber(...) cannot be combined with field(...) for other fields than bank and branch identifier. padAccountNumber(true) pads field(ACCOUNT_NUMBER, ...); it pads accountNumber(...) only where that is the national account number: for IT or ES padding would shift the CIN or the check digits, so a short value is rejected there with a hint to use the field. A field the country does not have is empty (Optional.empty()) and is rejected by the builder with UNDEFINED_FIELD.

Iban iban = Iban.parse("FR1420041010050500013M02606");
iban.field(BbanField.BRANCH_IDENTIFIER);       // Optional[01005]
iban.field(BbanField.ACCOUNT_NUMBER);          // Optional[0500013M026]
iban.field(BbanField.NATIONAL_CHECK_DIGITS);   // Optional[06]
iban.branchIdentifier();                       // Optional.empty: the registry defines no French branch

Iban.builder()
    .countryCode("FR")
    .bankIdentifier("20041")
    .branchIdentifier("01005")
    .field(BbanField.ACCOUNT_NUMBER, "0500013M026")
    .nationalCheckDigits(true)
    .build();                                  // FR1420041010050500013M02606

Iban.bankIdentifier() and Iban.branchIdentifier() keep following the registry, so for France and Portugal the branch is only available as a field.

Fields

FieldMeaning
BANK_IDENTIFIERbank identifier, always as in the registry
BANK_IDENTIFIER_EXTENSIONtrailing part of the bank identifier (Seychelles); lies inside the bank identifier
BRANCH_IDENTIFIERbranch identifier
ACCOUNT_NUMBERnational account number
NATIONAL_CHECK_DIGITSnational check digits; for AL and PL inside the registry branch or bank identifier
ACCOUNT_TYPEaccount type
OWNER_ACCOUNT_TYPEposition of the account holder (Brazil)
IDENTIFICATION_NUMBERidentification number of the holder (Icelandic kennitala)
CURRENCYISO 4217 currency code (Seychelles)
RESERVEDposition reserved for future use (Turkiye, currently 0)

Only BANK_IDENTIFIER_EXTENSION and NATIONAL_CHECK_DIGITS can lie inside another field. The builder accepts both the enclosing field and the nested one, as long as they agree.

Layouts

Countries without an entry below get the registry layout: bank and branch identifier as in the registry, the remaining positions as ACCOUNT_NUMBER (BbanLayout.isSupplemented() is false). The supplements are maintained by hand in BbanLayoutData; one that does not agree with the registry (BBAN length, bank identifier, registry branch identifier) is ignored, and BbanLayoutTest fails. Positions are BBAN positions.

CountryLayoutSource
ALbank 1-3, branch 4-8 (check digit 8), account 9-24Albanian account format: branch 4 digits and a check digit over bank and branch; the registry branch is 5 digits
BAbank 1-3, branch 4-6, account 7-14, check 15-16registry structure 3!n3!n8!n2!n; check digits ISO 7064 MOD 97-10
BEbank 1-3, account 4-10, check 11-12National Bank of Belgium, Belgian account number format
BGbank 1-4, branch 5-8, account type 9-10, account 11-18Bulgarian National Bank, Ordinance 3; registry structure 4!a4!n2!n8!c
BRbank 1-8, branch 9-13, account 14-23, account type 24, holder position 25SWIFT IBAN registry, Brazil; Banco Central do Brasil
DJbank 1-5, branch 6-10, account 11-21, key 22-23registry structure 5!n5!n11!n2!n
EEbank 1-2, account 3-15, check 16Estonian account number, check digit by the 7-3-1 method
ESbank 1-4, branch 5-8, check 9-10, account 11-20Código Cuenta Cliente (CCC)
FIbank 1-3, account 4-13, check 14Finnish account number in machine format
FObank 1-4, account 5-13, check 14registry structure 4!n9!n1!n
FRbank 1-5, branch 6-10, account 11-21, RIB key 22-23RIB (CFONB); the registry defines no branch
HUbank 1-3, branch 4-7, account 8-23, check 24registry structure 3!n4!n1!n15!n1!n; position 8, the check digit over bank and branch, stays in the account as in iban4j, because a layout has one check digit field
ISbank 1-2, branch 3-4, account type 5-6, account 7-12, kennitala 13-22registry structure 4!n2!n6!n10!n; Icelandic account format
ITCIN 1, ABI 2-6, CAB 7-11, account 12-23Banca d'Italia / ABI, coordinate bancarie
MCas FR (bank, branch from the registry)Monaco uses the French RIB
MEbank 1-3, account 4-16, check 17-18ISO 7064 MOD 97-10 national check digits
MKbank 1-3, account 4-13, check 14-15ISO 7064 MOD 97-10 national check digits
MRbank 1-5, branch 6-10, account 11-21, key 22-23registry structure 5!n5!n11!n2!n
NObank 1-4, account 5-10, check 11Norwegian kontonummer
PLbank 1-8 (check digit 8), account 9-24Polish sort code (bank 3, branch 4, check digit 1); the registry bank identifier is the whole sort code
PTbank 1-4, branch 5-8, account 9-19, check 20-21NIB (Banco de Portugal); the registry defines no branch
RSbank 1-3, account 4-16, check 17-18ISO 7064 MOD 97-10 national check digits
SCbank 1-6 (extension 5-6), branch 7-8, account 9-24, currency 25-27SWIFT IBAN registry, Seychelles (4!a2!n2!n16!n3!a)
SEbank 1-3, account 4-19, check 20registry structure 3!n16!n1!n
SIbank 1-5, account 6-13, check 14-15ISO 7064 MOD 97-10 national check digits
SKbank 1-4, account 5-20 (prefix 6 and basic number 10)Slovak account number; checks see national-checks.md
SMas ITSan Marino uses the Italian BBAN
TLbank 1-3, account 4-17, check 18-19registry structure 3!n14!n2!n
TNbank 1-2, branch 3-5, account 6-18, key 19-20Tunisian RIB
TRbank 1-5, reserved 6, account 7-22registry structure 5!n1!n16!c, position 6 reserved
XKbank 1-2, branch 3-4, account 5-14, check 15-16registry structure 4!n10!n2!n

Validating fields without an IBAN

Bban.validateField("DE", BbanField.BANK_IDENTIFIER, "37040044");   // valid
Bban.validateField("DE", BbanField.BANK_IDENTIFIER, "3704004X");   // INVALID_BBAN, position 8, expected DIGITS
Bban.validateField("DE", BbanField.NATIONAL_CHECK_DIGITS, "12");   // UNDEFINED_FIELD
Bban.validate("GB", "NWBK60161331926819");                         // the whole BBAN

Results distinguish EMPTY, INVALID_CHARACTER, INVALID_LENGTH, INVALID_BBAN (wrong character type), UNDEFINED_FIELD, INVALID_COUNTRY_CODE and UNSUPPORTED_COUNTRY. Positions of validateField count the characters of the field, positions of validate the characters of the BBAN (add 4 for the IBAN position). Both use the same structure and layout as Iban.validate, which BbanTest.consistentWithIbanValidation checks for every country.