-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Added isAbaRouting validator #2143
Changes from 1 commit
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,20 @@ | ||
import assertString from './util/assertString'; | ||
|
||
// http://www.brainjar.com/js/validation/ | ||
const isRoutingReg = /^[0-9]{9}$/; | ||
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. According to the ABA document [1] (page 4), there seems to be quite a few ranges, that are "reserved for future use", i.e. they are currently not valid ABA numbers, at least that is the way I would see it. I think it would make sense to adjust the RegExp accordingly to reflect that, what do you think? 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. Hi Panogiotis, You are right about this. I have just double-checked their latest article. I added a separate regex to filter out reserved routing numbers, so that it can be easily modified if reserved series is brought into assigned in the future. Thanks for your review! |
||
|
||
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.exec(str)) return false; | ||
songyuew marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const strArr = str.split(''); | ||
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. If I am not mistaken I don't think it is necessary to split the string's characters into an array -> |
||
let checkSumVal = 0; | ||
for (let i = 0; i < strArr.length; i++) { | ||
if (i % 3 === 0) checkSumVal += strArr[i] * 3; | ||
else if (i % 3 === 1) checkSumVal += strArr[i] * 7; | ||
else checkSumVal += strArr[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. 😁