format.iban
v0.1.0 latestFormat an IBAN (International Bank Account Number) in groups of 4 per ISO 13616.
Format an IBAN (International Bank Account Number) in groups of 4 per ISO 13616.
Signature
function iban(input: string, opt?: IBANFormatOptions): string | null
Type Definitions:
IBANFormatOptions— interface
Problem
IBANs are stored in electronic format (compact, no separators) but must be displayed in human-readable groups of 4 characters. Different systems output IBANs with inconsistent casing and separator patterns. Manual regex-based splitting fails on varying IBAN lengths across countries.
How It Works
Strips existing separators and uppercases per ISO 13616, validates basic structure (2-letter country + 2 check digits + alphanumeric BBAN), then re-groups in blocks of 4 with the specified separator. Electronic mode returns the compact uppercase form without separators.
Boundaries
- Does not verify IBAN check digits — formatting only.
- Returns null for empty, missing country prefix, or structurally invalid IBAN.
- Throws TypeError for non-string input.
Replaces
Common boilerplate this function replaces:
iban.toUpperCase().replace(/[\s-]/g, '').match(/.{1,4}/g).join(' ')
Examples
format.iban("DE89370400440532013000"); // "DE89 3704 0044 0532 0130 00"
format.iban("GB29 NWBK 6016 1331 9268 19"); // "GB29 NWBK 6016 1331 9268 19"
format.iban("DE89370400440532013000", { electronic: true }); // "DE89370400440532013000"
format.iban("DE89370400440532013000", { separator: "-" }); // "DE89-3704-0044-0532-0130-00"
format.iban(""); // null
Standards
Caveats
- Input is always uppercased in the output — ISO 13616 specifies uppercase representation.
- Structural validation checks for 'CC99XXXX…' pattern only; BBAN length per country is not enforced.
FAQ
How to format an IBAN with spaces in JavaScript?
format.iban('DE89370400440532013000') returns 'DE89 3704 0044 0532 0130 00' — groups of 4 characters separated by spaces.
How to get the electronic (compact) form of an IBAN?
Use electronic: true: format.iban('DE89 3704 0044 0532 0130 00', { electronic: true }) returns 'DE89370400440532013000'.
How to format an IBAN with dashes instead of spaces?
Use separator: '-': format.iban('DE89370400440532013000', { separator: '-' }) returns 'DE89-3704-0044-0532-0130-00'.
Does IBAN formatting validate the check digits?
No — format.iban() validates basic structure (country prefix + check digits + alphanumeric BBAN) but does not verify the mod-97 check digit computation.
How to normalize IBAN casing for display?
format.iban() always uppercases the output per ISO 13616, regardless of input casing.