Check that a UK bank account number is valid using the VocaLink UK specification
Modulus checking is a procedure for validating sort code and account number combinations. It doesn’t confirm that an account belongs to a customer or supports Direct Debit.
If you want to know more about modulus checking, read this GoCardless guide.
This package follows the Vocalink specification, version 5.50, that will be live on 18/03/2019. More information about the specification can be seen on the Vocalink website.
If you prefer to send request to a web service, take a look at the package moduluschecking-api that offers an API to validate UK bank account numbers, supporting authentication and rate limits.
The following institutions are supported:
This package ships with the latest version of the modulus weight table data and the sorting code substitution data. Both files can be found in the data
folder.
You can grab this package with the following command:
go get github.com/AntoineAugusti/moduluschecking/...
If you wanna use the default file parser:
package main
import (
"fmt"
"github.com/AntoineAugusti/moduluschecking/models"
"github.com/AntoineAugusti/moduluschecking/parsers"
"github.com/AntoineAugusti/moduluschecking/resolvers"
)
func main() {
// Read the modulus weight table and the sorting
// code substitution table from the folder data
parser := parsers.CreateFileParser()
// The resolver handles the verification of the validity of
// bank accounts according to the data obtained by the parser
resolver := resolvers.NewResolver(parser)
// This helper method handles special cases for
// bank accounts from:
// - National Westminster Bank plc (10 or 11 digits with possible presence of dashes, for account numbers)
// - Co-Operative Bank plc (10 digits for account numbers)
// - Santander (9 digits for account numbers)
// - banks with 6 or 7 digits for account numbers
bankAccount := models.CreateBankAccount("089999", "66374958")
// Check if the created bank account is valid against the rules
fmt.Println(resolver.IsValid(bankAccount))
}
On my personal laptop (MacBook Pro, Core i5 2.5 Ghz, 8 GB of RAM with a SSD):