I'm trying to check if a provided IBAN number is correct. While initially asking how to handle large numbers with the modulo operator, I stumbled across the fact, that I need to use the BigInt
datatype.
console.log(97009700101075 % 97) // gives the correct result 1
console.log(970097009700101075 % 97) // doesn't give the expected result of 1
// due to the number being too large for regular int
While this is an easy fix to one specific aspect of validating a provided IBAN, I am still wondering, if there is a better way of handling IBAN validation.
Here you can find a basic algorithm for validating an IBAN.
Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid
Move the four initial characters to the end of the string
Replace each letter in the string with two digits, thereby expanding the string, where A = 10, B = 11, ..., Z = 35
Interpret the string as a decimal integer and compute the remainder of that number on division by 97
What is a good way to
- split the IBAN string and move the first part to the end
- convert the first two letters to number, where A=10 and so on