ibanlib

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: MIT Imports: 8 Imported by: 0

README

Go Reference

simple iban lib for checking and generating IBANs

IBAN numbers are structured with per-country rules.

This lib can parse, check and generate IBAN following rules for various countries.

Documentation

Index

Constants

View Source
const (
	AlphaRange        = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	NumericRange      = "0123456789"
	AlphanumericRange = AlphaRange + NumericRange
)

Variables

View Source
var (
	ErrTooShort             = errors.New("IBAN too short")
	ErrTooLong              = errors.New("IBAN too long")
	ErrInvalidCountry       = errors.New("invalid or unknown IBAN country")
	ErrInvalidChecksum      = errors.New("invalid IBAN checksum")
	ErrInvalidBankLength    = errors.New("invalid IBAN bank id length")
	ErrInvalidBranchLength  = errors.New("invalid IBAN branch id length")
	ErrInvalidAccountLength = errors.New("invalid IBAN account id length")
)

Functions

func RandomValue

func RandomValue(acceptableRange string, length int) string

RandomValue return a low quality random value suitable for account numbers etc

func SetRandomSeed

func SetRandomSeed(n int64)

SetRandomSeed must not need to be used in normal operations, and is only useful to have tests that can be reproduced. By default we will use UnixNano() to initialize our random seed, so you really don't need to call this.

Types

type IBAN

type IBAN struct {
	Country string // 2 letters
	Check   string // 2 digits
	Bank    string // bank code
	Branch  string // branch or sort code
	Account string // account number
}

func Parse

func Parse(iban string) (*IBAN, error)

Parse will parse a given IBAN and always return a value, even if an error happens

func (*IBAN) BBAN

func (iban *IBAN) BBAN() string

BBAN returns the Basic Bank Account Number part of the IBAN

func (*IBAN) Checksum

func (iban *IBAN) Checksum() (int, error)

Checksum will compute the appropriate checksum value for the current iban value and return it.

func (*IBAN) CompactString

func (iban *IBAN) CompactString() string

CompactString returns a IBAN without any spaces/etc

func (*IBAN) IsValid

func (iban *IBAN) IsValid() error

IsValid will return nil if the iban is valid

func (*IBAN) SetChecksum

func (iban *IBAN) SetChecksum() error

SetChecksum will update the IBAN's checksum value to ensure it is valid

func (*IBAN) SetRandomAccount

func (iban *IBAN) SetRandomAccount() error

func (*IBAN) String

func (iban *IBAN) String() string

String returns a formatted IBAN

Jump to

Keyboard shortcuts

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