1.0.3 • Published 5 years ago

@fnzc/nz-bank-account-validator v1.0.3

Weekly downloads
312
License
MIT
Repository
github
Last release
5 years ago

nz-bank-account-validator

npm

A validator for New Zealand bank accounts

Installation

npm install --save @fnzc/nz-bank-account-validator

or

yarn add @fnzc/nz-bank-account-validator

Usage

Function requires four string parameters:

  • Bank ID
  • Bank Branch
  • Account Base
  • Suffix Returns a boolean.
var bankAccountValidator = require('@fnzc/nz-bank-account-validator');
bankAccountValidator.isValidNZBankNumber('00', '0000', '00000000', '000');

Algorithm

The algorithm is based on the 'Non-Resident Withholding Tax And Resident Withholding Tax Specification Document' issues by the Inland Revenue on the 31st of March 2016.

Bank account number validation

The bank account number format used by all banks is numeric and includes the following parts:

  • Bank ID (maximum 2 digits)
  • Bank branch (maximum 4 digits)
  • Account base number (maximum 8 digits)
  • Account suffix (maximum 4 digits).

For processing at Inland Revenue the fields for the individual account number parts are all of maximum size. If less than the maximum number of digits is supplied, then values are right justified and the fields padded with zeroes (where applicable).

The first step in the validation process is to verify the bank branch number. For every bank ID, a range of branch numbers is allocated. If the bank ID is not one of those listed below or the branch number is not included in the range(s) specified, the bank account number is invalid. If the branch number is valid, then derive the appropriate code from the “Algorithm” column below and perform the second validation step as outlined in the first paragraph over the page.

Bank IDValid Branch NumbersAlgorithm
010001 - 0999, 1100 - 1199, 1800 - 1899See note
020001 - 0999, 1200 - 1299See note
030001 - 0999, 1300 - 1399, 1500 - 1599, 1700 – 1799 , 1900 - 1999See note
042020 - 2024
060001 - 0999, 1400 - 1499See note
086500 - 6599D
090000E
105165 - 5169See note
115000 - 6499, 6600 - 8999See note
123000 - 3299, 3400 – 3499, 3600 - 3699See note
134900 - 4999See note
144700 - 4799See note
153900 - 3999See note
164400 - 4499See note
173300 - 3399See note
183500 - 3599See note
194600 - 4649See note
204100 - 4199See note
214800 - 4899See note
224000 - 4049See note
233700 - 3799See note
244300 - 4349See note
252500 - 2599F
262600 - 2699G
273800 - 3849See note
282100 - 2149G
292150 - 2299G
302900 - 2949See note
312800 - 2849X
336700 - 6799F
352400 - 2499See note
389000 - 9499See note
888800 - 8805

Note: If the account base number is below 00990000 then apply algorithm A, otherwise apply algorithm B.

The second validation step is a modulus n algorithm applied to the whole account number. The algorithm type is derived from the table on the previous page. Follow this process:

  • Identify the corresponding weight factor for every digit in the account number as showninthetablebelow. Note:allfields(iebankID,bankbranch,accountbase and account suffix) are right justified and padded with zeroes.
  • Add together the products of the weight factors and their associated account number digit. If the algorithm E or G is used then add the two digits of the product (tens and ones), and again the two digits of the result before summing (see example 3 on page 16).
  • Divide the sum by the value in the “Modulo” column below. If the remainder is zero then the bank account number is valid.
AlgorithmBankBranchAccount BaseSuffixModulo
A00637900A58421000011
B00000000A58421000011
C37000091A53421000011
D00000007654321000011
E00000000005432000111
F00000001731731000010
G00000001371371037110
X0000000000000000001

Note 1: Algorithm C is not currently used by the banks. Note 2: Algorithm X (for Bank ID 31) always verifies the bank account number to be valid. It is included in this table so the same validation logic can be applied to all account numbers.

Changelog

Contributing

Pull requests are welcome.

License

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago