swift package

import ""

package swift provides methods to check the validity of an IBAN (and retrieve the BIC for some countries).

// SPDX-FileCopyrightText: 2023 Olivier Charvin <>
// SPDX-License-Identifier: GPL-3.0-or-later

package main

import (


var germanTestIBAN = "DE75512108001245126199"

func main() {
	iban, err := swift.NewIBAN(germanTestIBAN, swift.CountryBelongsToSEPA())
	if err != nil {
	fmt.Println("IBAN:", iban.MaskedAndSpaced())
	fmt.Println("BIC: ", bic.FromIBAN(iban).String())


IBAN: DE75 512* **** **** ***1 99




ErrCountryNotInRegistry is returned when a country is not listed in the iban registry.

ErrCountryOutsideSEPA is returned when a country does not belong to the Single Euro Payments Area.

type BIC

BIC represents the routing information as specified by ISO 9362 (also known as Business Identifier Codes (BIC), SWIFT ID or SWIFT code, and SWIFT-BIC).

func NewBIC

NewBIC uppercases a BIC and perform some basic checks (format and length). If the country code is unknown, the BIC will be accepted.

func (BIC) String

String returns the BIC.

type CheckDigitsError

CheckDigitsError indicates that the checksum did not match the expected check digits.

func (CheckDigitsError) Error

type CountryCode

CountryCode is the ISO 3166-1 alpha-2 code of the country (uppercase)

func (CountryCode) BelongsToIBANRegistry

BelongsToIBANRegistry returns true if the country is listed in the iban registry

func (CountryCode) BelongsToSEPA

BelongsToSEPA indicates if a country belongs to the Single Euro Payments Area according to

type FormatError

FormatError indicates that an unexpected character type was encountered.

func (FormatError) Error

type IBAN

IBAN represents an International Bank Account Number

func NewIBAN

NewIBAN sanitizes, parses and checks an IBAN (length, format, check digit sum). See CountryBelongsToIBANRegistry and CountryBelongsToSEPA to perform country code validation. See NationalFormatCheck to additionnally verify the national format.

func (IBAN) MaskedAndSpaced

MaskedAndSpaced returns the spaced IBAN with only the first and last 3 characters of the BBAN visible (other chars are replaced with "*").

IBANs are not secret, but it shouldn't hurt to hide parts of them. Since BBANs are longer than 11 characters, at least 5 chars will be hidden (still partially recoverable using the leading check digits). Example:

DE75 512* **** **** ***1 99

func (IBAN) Spaced

Spaced returns the IBAN with spaces between every 4 characters.

func (IBAN) String

String returns the IBAN, without spaces

type IBANValidator

IBANValidator makes additional checks on a given IBAN.

func CountryBelongsToIBANRegistry

CountryBelongsToIBANRegistry ensures that the country is listed in the iban registry

func CountryBelongsToSEPA

CountryBelongsToSEPA ensures that the country belongs to the Single Euro Payments Area according to

func NationalFormatCheck

NationalFormatCheck checks the national rules (format and check digits), if there is a registered BBANChecker for this country code.

type TooShortError

TooShortError indicates that the provided string is shorter than expected.

func (TooShortError) Error

Source Files

bban.go bban_checkers.go bban_registry.go bic.go columns.go country.go errors.go iban.go


Path Synopsis
bic package bic computes the BIC from an IBAN (for supported countries).
internal/bic-generate bic-generate generates the exposed bic package from bank BIC listings.
internal/format package format is used internally to describe the format of an IBAN.
internal/registry-generate registry-generate generates the bban and country checkers from the SWIFT IBAN registry.


git clone