iban

package module
v0.0.0-...-862a795 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: MIT Imports: 4 Imported by: 0

README

iban

GoLang IBAN Validation module

The separate BBAN ckeck is not yet implemented. This is needed for the countries where the IBAN ckecksum is a constant. Currently the validation will work but the constant is not checked and neiter the BBAN. Concerned countries: Macedonia, Bosnia and Herzegovina, East Timor, Mauritania, Montenegro, Portugal, Slovenia, Tunisia

The IBAN may be formated with spaces. Letter cases are ignored.

Here a small sample to test it.

package main

import (
	"fmt"
	"github.com/go-pascal/iban"
)

func main() {

	var OK, well_formated, err = iban.IsCorrectIban("GB82 WEST 1234 5698 7654 32 ", true) // passed: IBAN string , debug true/false
	if err != nil {
		fmt.Println(err.Error())
	} else {

		if OK {
			fmt.Printf("IBAN %s is valid \n\r", well_formated)
		} else {
			fmt.Println("IBAN is not valid")
		}
	}

	var ck, err2 = iban.GetIbanChecksum("GB00 WEST 1234 5698 7654 32 ")
	if err2 != nil {
		fmt.Println(err2.Error())
	} else {

		fmt.Println("IBAN checksum :", ck)
	}
}
package main

import "github.com/RitchieFlick/iban"
import "log"

func main() {
	iban, err := iban.NewIBAN("GB82WEST12345698765432")
	if err != nil {
		log.Print(err)
	}
	log.Print(iban.Number)
}

Documentation

Overview

Package iban contains utility functions for working with IBAN account numbers.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidIBAN = errors.New("Invalid IBAN number received")

ErrInvalidIBAN is returned when an invalid IBAN number was received

Functions

func GetIbanChecksum

func GetIbanChecksum(iban string) (int, error)

GetIbanChecksum returns the checksum of the given iban number.

func IsCorrectIban

func IsCorrectIban(iban string, debug bool) (isValid bool, wellFormated string, err error)

IsCorrectIban checks if the given iban number corresponds to the rules of a valid iban number and also returns a properly formated iban number string.

Types

type IBAN

type IBAN struct {
	Number      string
	CountryCode string
	Checksum    string
	BBAN        string
	BankCode    string
}

IBAN represents an IBAN number, split up into its different parts.

func NewIBAN

func NewIBAN(ibanNumber string) (IBAN, error)

NewIBAN creates a new instance of IBAN and checks before if the IBAN number is actually valid or not.

Jump to

Keyboard shortcuts

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