-
-
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
Fix A-z ranges #1625
Merged
Merged
Fix A-z ranges #1625
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import assertString from './util/assertString'; | ||
import { CountryCodes } from './isISO31661Alpha2'; | ||
|
||
const isBICReg = /^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/; | ||
// https://en.wikipedia.org/wiki/ISO_9362 | ||
const isBICReg = /^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/; | ||
|
||
export default function isBIC(str) { | ||
assertString(str); | ||
|
||
// toUpperCase() should be removed when a new major version goes out that changes | ||
// the regex to [A-Z] (per the spec). | ||
if (CountryCodes.indexOf(str.slice(4, 6).toUpperCase()) < 0) { | ||
return false; | ||
} | ||
|
||
return isBICReg.test(str); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 work here.
I like the simplicity, but I could offer an alternative based on fact that the second part is country code addition i.e:
-> We could leverage the array in
validISO31661Alpha2CountriesCodes
for making this a robust validator.CC. @tux-tn and @profnandaa
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.
i'm happy to make a change doing this - i think it's a good idea. i would just return false without executing the
isBICReg.test(str)
if it's not a country code - no reason to execute the test if we already know the answer.it's not clear to me why using
includes
is useful though; is there a compatibility issue somewhere that i'm not aware of? this seems like it should be a straight, simple use ofindexOf()
- some has to call a function each time but even then why replacesome()
withincludes()
to does the exact same thing but with an extra layer of a function call.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.
That is great. And I am happy that you are willing to make these changes.
First, I would like to say that, the code above was a sample and required more modifications.
validISO31661Alpha2CountriesCodes
from isISO31661Alpha2 and create a new file insidelib/util
. Import for both isISO31661Alpha2 and BIC validators.indexOf()
instead ofincludes()
andsome()
I am happy to review that and give a go-ahead to merge this PR.
Thanks again for your contributions @bmacnaughton.
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.
i think this is ready to be merged. it made sense to check that the bank ID was valid.