# IBAN validation and big numbers

Hi everyone! Our team will collect data for financial aid for IDPs in Ukraine. I try to create a field for IBAN. We need to set validation for IBAN to exclude mistakes. But it needs big numbers calculations. For example, this is the algorithm for IBAN validation according to the ISO 7064 standard:

MOD (3996220004149005233566882301093; 97) =
3996220004149005233566882301093 – 97 ∗ INT (3996220004149005233566882301093 / 97)
= 1

But when I convert it to Kobo’s formula, it doesn’t work correctly because it needs to calculate too big numbers:
\${n} - 97 * int(\${n} div 97)

In Google Sheets I resolve big number calculation problem with scripts. Help me please fix it in Kobo!

This does not work correctly too:
\${n} mod 97

The result must be 1 but it writes 15

Yes, the underlying problem is that you are ostensibly limited to 32-bit integers (aka long int) in math operations by the underlying XPath expression engine (and why the docs say “the integer widget has a limit of nine digits…”).

Unfortunately there is no immediate workaround for performing, say, 64-bit integer (aka long long int) math expressions. However, because you are ultimately trying to do modulus arithmetic, and you are dealing with a fixed number of digits in an IBAN number, it may be possible that you can implement a modulus algorithm that keeps all its calculations within long ints.

Note, these algorithms will typically involved iterating over all the base 10 digits in your large integer with a loop, which you cant do in XPath. But because you have a fixed number of digits you can always unroll the loop for however many iterations are required. It’ll be messy, but if you are desperate…

Poke around the web and see if you can find a suitable modulus algorithm for large integers; eg this looks promising: javascript - Modulo operation on a very large number - Stack Overflow

1 Like

Thanks! This is brilliant! I was looking for something similar to column division. I will show the final solution later!

2 Likes

Please do! It’s an interesting problem, and being able to perform data validation in the field is really important. I’ll be very curious to see a working solution to it.

1 Like

It works!
I hope it helps someone!
IBAN validation (Kobo).xlsx (6.5 KB)

1 Like

Boy, those are some REALLLLLLLLLLLLY long `if` statements!