Last active
August 17, 2020 12:20
-
-
Save yannamsellem/7aa626652700faf60a8c1bc57093cb6f to your computer and use it in GitHub Desktop.
check iban validity
This file contains hidden or 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
| /** @param {string} iban */ | |
| function isValidIban(iban) { | |
| const correspond = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
| const withoutSpace = iban.replace(/ /g, '').toUpperCase() | |
| const rearranged = withoutSpace.slice(4) + withoutSpace.slice(0, 4) | |
| const computedRemainder = rearranged | |
| .replace(/[a-z]/gi, m => correspond.indexOf(m) + 10) | |
| .match(/([0-9]{9})([0-9]{7})([0-9]{7})([0-9]{5})/) | |
| .slice(1) | |
| .reduce((acc, k) => String(parseInt(acc + k, 10) % 97), '') | |
| return computedRemainder === '1' | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit
IBAN - Wiki followed step by step