-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added isAbaRouting validator (#2143)
Added isAbaRouting validator, new validator. Check whether a string is ABA routing number for US bank account & cheque ref: https://en.wikipedia.org/wiki/ABA_routing_transit_number
- Loading branch information
Showing
4 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import assertString from './util/assertString'; | ||
|
||
// http://www.brainjar.com/js/validation/ | ||
// https://www.aba.com/news-research/research-analysis/routing-number-policy-procedures | ||
// series reserved for future use are excluded | ||
const isRoutingReg = /^(?!(1[3-9])|(20)|(3[3-9])|(4[0-9])|(5[0-9])|(60)|(7[3-9])|(8[1-9])|(9[0-2])|(9[3-9]))[0-9]{9}$/; | ||
|
||
export default function isAbaRouting(str) { | ||
assertString(str); | ||
|
||
if (!isRoutingReg.test(str)) return false; | ||
|
||
let checkSumVal = 0; | ||
for (let i = 0; i < str.length; i++) { | ||
if (i % 3 === 0) checkSumVal += str[i] * 3; | ||
else if (i % 3 === 1) checkSumVal += str[i] * 7; | ||
else checkSumVal += str[i] * 1; | ||
} | ||
return (checkSumVal % 10 === 0); | ||
} |
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