-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added isAbaRouting validator #2143
Changes from 3 commits
cf43c44
ffe041e
2a5b111
31acc53
b7dd3a7
4bf84a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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); | ||
str = str.trim(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry about not noticing before, but I would say that Otherwise you might end up with a scenario as below:
Does that make sense? |
||
|
||
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, this is just for US only? Do we plan to support other countries and should we have a locale param then?
Sorry missed this in my previous review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, ABA is the abbv for American Bankers Association. The ABA number is used with every US bank account and cheque, to identify the corresponding financial institution. For example:
There is no need to add the locale param.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does any other country have a similar thing perhaps just with a different name? Trying to see if there's a way we could generalize here than having a whole validator just for one country...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea. I'll look into it. 😁