iban

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package iban provides parsing and validation for International Bank Account Numbers (IBAN).

It can validate the country code, checksum, and country-specific length and checksum (if the country has one).

For countries for which no information is available, it only validates the country code and checksum.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLength           = errors.New("iban: an iban must be at least 5 and at most 34 characters long")
	ErrCountryCode      = errors.New("iban: invalid country code")
	ErrChecksum         = errors.New("iban: checksum does not match")
	ErrCountrySpecific  = errors.New("iban: bban does not match country-specific rules")
	ErrNationalChecksum = errors.New("iban: national checksum does not match")
	ErrBBAN             = errors.New("iban: bban must consist of only letters and digits")
)

Functions

func IsValid added in v0.2.0

func IsValid(s string) bool

Types

type IBAN

type IBAN struct {
	// CountryCode is the ISO 3166-1 alpha-2 country code of the IBAN.
	CountryCode iso3166.Alpha2Code
	// Checksum is the checksum of the IBAN.
	Checksum uint8
	// BBAN is the Basic Bank Account Number of the IBAN.
	BBAN string

	BankCode                  string
	BranchCode                string
	AccountType               string
	OwnerAccountNumber        string
	OwnerIdentificationNumber string // e.g. kennitala in Iceland
	BalanceAccountNumber      string
	AccountNumberPrefix       string
	AccountNumber             string
	NationalChecksum          string
	CurrencyCode              string
}

IBAN represents an International Bank Account Number.

func Parse

func Parse(s string) (IBAN, error)

Parse parses the passed IBAN.

Spaces are ignored and input is treated as case-insensitive, however, the returned IBAN will always be uppercase.

Validation

If Parse returns without an error, the IBAN is considered syntactically valid.

This means that the country code is valid, the checksum is correct, and the IBAN does not exceed the 34-character limit.

If country-specific rules are available, Parse will also validate the country-specific length of the IBAN, the correct format (i.e. ensure that numeric parts only contain digits, and alphabetic parts only contain letters), and the national checksum, if there is one. See IBAN formats by country for the rules employed by Parse.

func (IBAN) Compact added in v0.5.0

func (iban IBAN) Compact() string

func (IBAN) MarshalText

func (iban IBAN) MarshalText() ([]byte, error)

func (IBAN) String

func (iban IBAN) String() string

String pretty-prints the IBAn by inserting spaces after every 4 characters.

If len(IBAN)%4 != 0, then the last group will be shorter than 4 characters.

func (*IBAN) UnmarshalText

func (iban *IBAN) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL