I'm a jscript newbie and I've a problem.
I'm writing a script to validate an IBAN bank account number in Belgium. I need to replace some letters by their position in a searchstring and afterwards I convert this string into a number to take the modulo 97 test.
The first part goes well, but afterwards with the conversion from string to number, 10 is added to my number. I don't know what I'm doing wrong.
function checkIBAN()
{
var iban = crmForm.all.fp_iban.DataValue;
if (iban != null)
{
iban = iban.substring(4) + iban.substring(0, 4);
iban = iban.toUpperCase();
var searchString = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var pos;
var tmp = '';
for (x = 0; x < iban.length; x++) {
pos = searchString.search(RegExp(iban.charAt(x),'i'));
if (pos == -1)
return false;
else
tmp += pos.toString();
}
alert(tmp); // Here my value is 735320036532111490
var nr =parseInt(tmp);
alert(nr); // Now my value seems to be 735320036532111500
alert(nr % 97);
if (nr % 97 != 1)
{
alert('IBAN number is not correct !');
}
}
}
Yes, 735320036532111490 is simply too great a value to store in an int. It'll always be rounded:
alert(735320036532111490 / 10);
// alerts 73532003653211150
Here's a solution that might work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With