Skip to content

Instantly share code, notes, and snippets.

@yannamsellem
Last active August 17, 2020 12:20
Show Gist options
  • Select an option

  • Save yannamsellem/7aa626652700faf60a8c1bc57093cb6f to your computer and use it in GitHub Desktop.

Select an option

Save yannamsellem/7aa626652700faf60a8c1bc57093cb6f to your computer and use it in GitHub Desktop.
check iban validity
/** @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'
}
@yannamsellem

Copy link
Copy Markdown
Author

Credit

IBAN - Wiki followed step by step

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment