Skip to content
Open site navigation sidebar
Go to GoCardless homepage
Pricing
LoginSign up
Go to GoCardless homepage
LoginSign up
Breadcrumb
Resources

Ibandit: simple IBAN manipulation

Grey Baker
Written by

Last editedApr 2020

We just open-sourced Ibandit, a simple library for working with [IBANs].

Usage

Constructing an IBAN from national details:

iban = Ibandit::IBANBuilder.build(
  country_code: 'GB',
  bank_code: 'BARC', # optional if a BIC finder is configured
  branch_code: '200000',
  account_number: '55779911'
)

iban.iban
# => "GB60BARC20000055779911"

Deconstructing an IBAN into national details:

iban = Ibandit::IBAN.new("GB82 WEST 1234 5698 7654 32")

iban.country_code
# => "GB"
iban.check_digits
# => "82"
iban.bank_code
# => "WEST"
iban.branch_code
# => "123456"
iban.account_number
# => "98765432"
iban.iban_national_id
# => "WEST98765432"

Validating an IBAN's format and check digits (national modulus checks are NOT applied):

iban = Ibandit::IBAN.new("GB81 WEST 1234 5698 7654 32")

iban.valid?
# => false
iban.errors
# => { check_digits: "Check digits failed modulus check. Expected '82', received '81'"}

Why convert to/from IBAN

IBANs are used for all SEPA payments, such as the collection of SEPA Direct Debit payments, but most people only know their national bank details. Further, most countries have validations which apply to their national details, rather than to IBANs.

Ibandit lets you work with national details when communicating with your customers, but with IBANs when communicating with the banks. Its conversions are based on data provided by SWIFT and our experience at GoCardless, and it's heavily commented with descriptions of each country's national bank details. Internally, we use it as our standard interface for "bank details".

Given an IBAN Ibandit can also validate the format and IBAN check digit, and can deconstruct the IBAN so country-specific checks can be applied. It is not a modulus checking gem, and will not perform national modulus checks, but it does include implementations of some of these checks.

Other libraries

Another gem, iban-tools, also exists and is an excellent choice if you only require basic IBAN validation. However, iban-tools does not provide a comprehensive, consistent interface for the construction and deconstruction of IBANs into national details.

We're hiring developers

See job listing

Over 85,000 businesses use GoCardless to get paid on time. Learn more about how you can improve payment processing at your business today.

Get StartedLearn More
Interested in automating the way you get paid? GoCardless can help
Interested in automating the way you get paid? GoCardless can help

Interested in automating the way you get paid? GoCardless can help

Contact sales