Skip to content

Instantly share code, notes, and snippets.

@JacobJohansen
Created November 1, 2017 13:25
Show Gist options
  • Save JacobJohansen/4f2530acb2e09ef98f299e6ec05a3c61 to your computer and use it in GitHub Desktop.
Save JacobJohansen/4f2530acb2e09ef98f299e6ec05a3c61 to your computer and use it in GitHub Desktop.
Bank Routing Checksum; ABA Routing checksum; Clean
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;
}
@JacobJohansen
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment