IbanGen

A Julia package for generating and validating IBANs.


Installation

IbanGen is a registered package and can be installed via Pkg.add:

Pkg.add("IbanGen")

General

The International Bank Account Number standard is described in Wikipedia in some detail, see Reference.

An IBAN consists of a two character country code, followed by a two digit redundancy code (AKA "check digits"), followed by a Basic Bank Account Number (BBAN) – an up to 30 alphanumeric character long string that is country specific.

The overall IBAN structure is then <country code><check digits><BBAN>. The country-by-country attribute format of the BBANs is captured in the IBAN registry document. All countries define a BankCode and AccountNumber structures, but some have additional attributes such as BranchCode, NationalCheckDigit, AccountType and IdentificationNumber.

IbanGen is aware of these definitions and takes them into account when parsing and validating the input. The IBAN generating functions ( iban and iban_random ) return a dictionary with keys that are the BBAN attribute names along with: CountryCode, CheckDigitsand value. The last one is the string representation of the IBAN:

julia> iban_random(CountryCode = "DE")
Dict{String,String} with 5 entries:
  "CountryCode"   => "DE"
  "AccountNumber" => "2619193797"
  "value"         => "DE37570047482619193797"
  "BankCode"      => "57004748"
  "CheckDigits"   => "37"

IBAN generating functions, will throw a ValidationException if they fail to validate the input, for example:

julia> iban_random(CountryCode = "DE", BankCode = "XX004748")
ERROR: ValidationException value: "XX004748"
invalid characters [Iban.BankCode]

A note about validation

In the context of IbanGen, an IBAN is valid if it matches the syntactic definition in the IBAN Registry( see Reference ) and makes no claims about semantic correctness. Following the example of iban_random(CountryCode = "DE"), the generated BankCode is valid in that it is a numeric string of length 8 - it is unlikely to be a code of an actual bank. The same applies to AccountNumber which is a numeric string of length 10 but does not represent a real account.


Library

IbanGen.ibanFunction
iban(
    CountryCode::String,
    BankCode::String,
    AccountNumber::String,
    BranchCode::Maybe{String}=nothing,
    NationalCheckDigit::Maybe{String}=nothing,
    AccountType::Maybe{String}=nothing,
    OwnerAccountType::Maybe{String}=nothing,
    IdentificationNumber::Maybe{String}=nothing,
)::Dict{String,String}

Generate an IBAN based on the provided parameters.

Example

julia> iban(CountryCode = "GB", BankCode = "NWBK", BranchCode = "601613",AccountNumber = "31926819")
Dict{String,String} with 6 entries:
  "CountryCode"   => "GB"
  "BranchCode"    => "601613"
  "AccountNumber" => "31926819"
  "value"         => "GB29NWBK60161331926819"
  "BankCode"      => "NWBK"
  "CheckDigits"   => "29"  
  
source
iban(iban_str::String)::Dict{String,String}

Validated the provided string and parse it into an IBAN structure.

Example

julia> iban("BR9700360305000010009795493P1")
Dict{String,String} with 8 entries:
  "CountryCode"      => "BR"
  "CheckDigits"      => "97"
  "BranchCode"       => "00001"
  "AccountType"      => "P"
  "AccountNumber"    => "0009795493"
  "value"            => "BR9700360305000010009795493P1"
  "BankCode"         => "00360305"
  "OwnerAccountType" => "1"
source
IbanGen.iban_randomFunction
iban_random(
    CountryCode::Maybe{String}=nothing,
    BankCode::Maybe{String}=nothing,
    AccountNumber::Maybe{String}=nothing,
    BranchCode::Maybe{String}=nothing,
    NationalCheckDigit::Maybe{String}=nothing,
    AccountType::Maybe{String}=nothing,
    OwnerAccountType::Maybe{String}=nothing,
    IdentificationNumber::Maybe{String}=nothing
)::Dict{String,String}

Generate a random IBAN subject to the provided attributes. For an attributes that is not provided, a random value will be used according to the rules of the (provided or generated) country. Attributes that are not defined for a country are ignored.

Example

julia> iban_random()
Dict{String,String} with 6 entries:
  "CountryCode"   => "GR"
  "BranchCode"    => "7500"
  "AccountNumber" => "1HRB7OApF5ABTOYH"
  "value"         => "GR8410975001HRB7OApF5ABTOYH"
  "BankCode"      => "109"
  "CheckDigits"   => "84"

julia> iban_random(CountryCode = "GR", BankCode = "109")
Dict{String,String} with 6 entries:
  "CountryCode"   => "GR"
  "BranchCode"    => "2170"
  "AccountNumber" => "24wO2qBgz1ROP82L"
  "value"         => "GR26109217024wO2qBgz1ROP82L"
  "BankCode"      => "109"
  "CheckDigits"   => "26"
source
IbanGen.is_supported_countryFunction
is_supported_country(country_code)::Bool

Return a boolean indicating if the country identified by country_code is supported.

Examples

julia> is_supported_country("DE")
true

julia> is_supported_country("ZZ")
false
source
IbanGen.ValidationExceptionType
ValidationException

Thrown when parameters to generate an IBAN fail validation. Reports the problematic value and the matching BBAN attribute

Example

julia> iban_random(CountryCode = "GR", BankCode = "xxx")
ERROR: ValidationException value: "xxx"
invalid characters [IbanGen.BankCode]  
source

Reference


License

Iban.jl is a port of iban4j, a Java library published under Apache 2 license and copyrighted 2015 Artur Mkrtchyan

Copyright 2021 David Soroko except where stated otherwise in the source.

Licensed under the Apache License, Version 2.0