Skip to content
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(isIBAN): add isIBAN feature #1034

Closed
wants to merge 2 commits into from

Conversation

NizarGhazouani
Copy link

Hello,
I added a feature to check the validity of an IBAN number: isIBAN.
To check the IBAN I verify if it corresponds to the structure of each country. Then I make the calculation to validate it according to the ISO 7064 (algorithms for calculating check digit characters.) by performing a basic mod-97 operation :

  1. Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid

  2. Move the four initial characters to the end of the string

  3. Replace each letter in the string with two digits, thereby expanding the string, where A = 10, ..., Z = 35

  4. Interpret the string as a decimal integer and compute the remainder of that number on division by 97

If the remainder is 1, the check digit test is passed and the IBAN might be valid.

N.B: the maximum length of an IBAN is equal to 34 characters and usual computer can't handle calculations using integers of more than 20 digits that's why I used a step by step calculations :

  1. Starting from the leftmost digit, construct a number using the first 9 digits and calculate its mod 97

  2. Construct a new 9-digit by concatenating above the result with the next 7 digits (or less)

  3. Repeat until all the digits have been processed

Ressources:

related to #951

check if the string is IBAN number,

(locale is one of ['AD','AT','BH','BE','BA','BG','CY','CZ','DE','DK','EE','FO','FI','FR','GB','GE','GI','GL','GR','HU','HR','IE','IS','IT',TN] OR defaults to 'any'. If 'any' or a falsey value is used, function will check if any of the locales match with the first two letters of the IBAN which coincide with the country Alpha-2 code name).
Copy link
Member

@profnandaa profnandaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Here are my preliminary comments.

@@ -72,87 +72,88 @@ Thank you to the people who have already contributed:

Here is a list of the validators currently available.

Validator | Description
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better diffing, just change the section involving isIBAN as opposed to reformatting the whole README.

@@ -14,7 +14,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
var phones = {
'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/,
'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
'ar-EG': /^((\+?20)|0)?1[012]\d{8}$/,
'ar-EG': /^((\+?20)|0)?1[0125]\d{8}$/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, separate out this and the change on L51 in a different PR.

@@ -15,7 +15,8 @@ function test(options) {
if (validator[options.validator](...args) !== true) {
let warning = format(
'validator.%s(%s) failed but should have passed',
options.validator, args.join(', ')
options.validator,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also unstage all the unrelated linting on this file for the time being.

});

test({
validator: 'isMobilePhone',
validator: 'isIBAN',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff here is a little off because of the extra linting done. It should be okay if you just add the isIBAN tests without linting the file.

@profnandaa profnandaa added 🧹 needs-update For PRs that need to be updated before landing and removed 🕑 to-be-reviewed labels Jun 13, 2019
ezkemboi added a commit to ezkemboi/validator.js that referenced this pull request Aug 11, 2019
- fix linter issues
- fix tests
- seperate unnecessary files changes
- closes validatorjs#1034 validatorjs#951
- Other references validatorjs#1071
@ezkemboi ezkemboi mentioned this pull request Aug 11, 2019
ezkemboi added a commit to ezkemboi/validator.js that referenced this pull request Aug 11, 2019
- fix linter issues
- fix tests
- seperate unnecessary files changes
- closes validatorjs#1034 validatorjs#951
- Other references validatorjs#1071
ezkemboi added a commit to ezkemboi/validator.js that referenced this pull request Aug 11, 2019
- fix linter issues
- fix tests
- seperate unnecessary files changes
- closes validatorjs#1034 validatorjs#951
- Other references validatorjs#1071
ezkemboi added a commit to ezkemboi/validator.js that referenced this pull request Aug 11, 2019
- fix linter issues
- fix tests
- seperate unnecessary files changes
- closes validatorjs#1034 validatorjs#951
- Other references validatorjs#1071
@profnandaa
Copy link
Member

Closing since there's a clean-up PR raised.

@profnandaa profnandaa closed this Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧹 needs-update For PRs that need to be updated before landing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants