Skip to content

Commit

Permalink
fix(isIBAN): only strip spaces and hyphens before validating IBAN (#1268
Browse files Browse the repository at this point in the history
)
  • Loading branch information
GoMino committed Mar 15, 2020
1 parent afafb54 commit 04769b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib/isIBAN.js
Expand Up @@ -94,12 +94,12 @@ const ibanRegexThroughCountryCode = {
* @return {boolean}
*/
function hasValidIbanFormat(str) {
// Strip white spaces and hyphens, keep only digits and A-Z latin alphabetic
const strippedStr = str.replace(/[^A-Z0-9]+/gi, '').toUpperCase();
// Strip white spaces and hyphens
const strippedStr = str.replace(/[\s\-]+/gi, '').toUpperCase();
const isoCountryCode = strippedStr.slice(0, 2).toUpperCase();

return (isoCountryCode in ibanRegexThroughCountryCode) &&
ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions test/validators.js
Expand Up @@ -3825,6 +3825,9 @@ describe('Validators', () => {
invalid: [
'XX22YYY1234567890123',
'FR14 2004 1010 0505 0001 3',
'FR7630006000011234567890189@',
'FR7630006000011234567890189😅',
'FR763000600001123456!!🤨7890189@',
],
});
});
Expand Down

0 comments on commit 04769b5

Please sign in to comment.