abavalidator
Version:
A validation module for browsers and Node.js to validate an American Bankers Association Routing Number used in ACH payments.
18 lines (14 loc) • 347 B
text/typescript
;
export function validate(routingNumber: string): boolean {
const match = routingNumber.match(/^\s*([\d]{9})\s*$/);
if (!match) {
return false;
}
const weights = [3, 7 ,1];
const aba = match[1];
let sum = 0;
for (let i=0 ; i<9 ; ++i) {
sum += +aba.charAt(i) * weights[i % 3];
}
return (sum !== 0 && sum % 10 === 0);
}