Simplified Validation of Bank Routing Numbers
Category:
C#, VB.NET, ASP.NETType:
SnippetsDifficulty:
BeginningAuthor:
David SchofieldVersion Compatibility: Visual Basic 6, Visual Basic 5, Visual Basic.NET
More information:
This is a direct implementation of the algorithm used to validate 9 digit Bank Routing numbers (aka Transit numbers).
Note that the routing number string passed to the routine should only consist of digits (ie. it should be pre-cleaned and scrubbed to remove spaces, dashes, etc.)
It returns True if the routing number is valid, false if not.
Theory:
The check digit scheme used on routing numbers for Electronic Funds Transfer (EFT) between banks uses a 9-digit number with position weightings of 3, 7, and 1. The check equation for a number a1a2a3a4a5a6a7a8a9 is
3a1 + 7a2 + a3 + 3a4 + 7a5 + a6 + 3a7 + 7 a8 + a9 mod 10 = 0
This scheme is based on the fact that multiplication modulo 10 yields a permutation of all 10 decimal digits if the multiplication factor is one of the digits 1, 3, 7, or 9, but only a subset of the decimal digits if the factor is 5 or an even digit, as illustrated in the following table:
Multiplication
modulo 10
0 1 2 3 4 5 6 7 8 9
1 0 1 2 3 4 5 6 7 8 9
3 0 3 6 9 2 5 8 1 4 7
7 0 7 4 1 8 5 2 9 6 3
9 0 9 8 7 6 5 4 3 2 1
Note that this scheme cannot detect adjacent transpositions of digits that differ by 5.
Test routing numbers include 222371863, 307075259, 052000113
Instructions: Copy the declarations and code below and paste directly into your VB project.
Declarations: