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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(isIBAN): only strip spaces and hyphens before validating IBAN #1268

Merged
merged 1 commit into from Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -3823,6 +3823,9 @@ describe('Validators', () => {
invalid: [
'XX22YYY1234567890123',
'FR14 2004 1010 0505 0001 3',
'FR7630006000011234567890189@',
'FR7630006000011234567890189馃槄',
'FR763000600001123456!!馃え7890189@',
],
});
});
Expand Down