-
-
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
feat: implement isIBAN(str) validator #1243
Conversation
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.
Generally solid work on this one, thanks for your contrib! 🎉 Just a few comments from me.
lib/isIBAN.js
Outdated
* Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number | ||
*/ | ||
var ibanRegexThroughCountryCode = { | ||
AL: /^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/, |
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.
Could you re-arrange these codes in alphabetical order to make it easy for reading and later contributions?
var strippedStr = str.replace(/[^A-Z0-9]+/gi, '').toUpperCase(); // Keep only digits and A-Z latin alphabetic | ||
|
||
var rearranged = strippedStr.slice(4) + strippedStr.slice(0, 4); | ||
var alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, function (char) { |
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.
Could make use of the ES6 features here for code succinctness if you don't mind, eg.
.replace(/[A-Z]/g, char => char.charCodeAt(0) - 55);
Same to line 133.
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.
@profnandaa Thanks for your feedback! I'm already using ES6 features for code succinctness (i.e. arrow functions) in both of the locations you've pointed-out back in src/lib/isIBAN.js
where the implementation lies, see here: https://github.com/validatorjs/validator.js/pull/1243/files#diff-ce49d7aaa9466099bb72b0307133b63dR121-R124
the above file lib/isIBAN.js
is auto-generated when running tests through npm test
, as the #CONTRIBUTING sections of README.md
implies:
files in lib/ folder are autogenerated when running tests (npm test) and need not to be changed manually.
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.
Sorry, my bad. I reviewed the wrong part of code. You are right, thanks!
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.
@profnandaa No problem! All is good 👍
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.
LGTM
isIBAN(str)
to validate IBAN (International Bank Account Number) strings.