Created
November 1, 2017 13:25
-
-
Save JacobJohansen/4f2530acb2e09ef98f299e6ec05a3c61 to your computer and use it in GitHub Desktop.
Bank Routing Checksum; ABA Routing checksum; Clean
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isValidRoutingNumber(routingNum) { | |
var ABA_CHECKSUM_CONSTANTS = [3, 7, 1]; | |
var ABA_CHECKSUM_DIVIDER = 10; | |
var ABA_LENGTH = 9; | |
var i = 0; | |
var checksum = 0; | |
if (isNaN(routingNum) || routingNum.length !== ABA_LENGTH) { | |
return false; | |
} | |
for (i = 0; i < routingNum.length; i++) { | |
checksum += parseInt(routingNum[i].toString()) * ABA_CHECKSUM_CONSTANTS[i % ABA_CHECKSUM_CONSTANTS.length]; | |
} | |
return checksum !== 0 && checksum % ABA_CHECKSUM_DIVIDER === 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Checksum reasoning https://www.azcode.com/aba/aba.htm