To check if a banknumber is valide I need to do a check. The result of the check should be a whole number (no digits).
Is there a simple way to check if a result is a whole number?
To check if a banknumber is valide I need to do a check. The result of the check should be a whole number (no digits).
Is there a simple way to check if a result is a whole number?
This is a way to do it:
var n1 = 12345.5;
var n2 = parseInt(n1 + "");
application.output("result = " + (n1 == n2));
The first is your original number. You force it into an integer and when they are equal the original is really a whole number (integer) otherwise a number…
Thanks, works great!
BTW you can also use our tools plugin:```
plugins.it2be_tools.isInteger(string);
Michel,
You also have to check if it’s a valid Dutch bankaccount number by performing the socalled 11-check.
You can find it’s algorithm in the Equens (formery Interpay) Clieop03 documentation. Below I included the calculation in a Winbatch script format. You can easily translate that to Servoys javascript.
#definefunction Banknr11proef(reknr)
L = Strlen(reknr)
if L > 10 then return -1
if L < 10 then
reknr = Strcat(Strfill(“0”, 10-L), reknr)
endif
som = 0
som = som + strsub(reknr, 1, 1)*10
som = som + strsub(reknr, 2, 1)*9
som = som + strsub(reknr, 3, 1)*8
som = som + strsub(reknr, 4, 1)*7
som = som + strsub(reknr, 5, 1)*6
som = som + strsub(reknr, 6, 1)*5
som = som + strsub(reknr, 7, 1)*4
som = som + strsub(reknr, 8, 1)*3
som = som + strsub(reknr, 9, 1)*2
som = som + strsub(reknr, 10, 1)*1
remainder = som mod 11
if remainder == 0 then
return @true
else
return @false
endif
#Endfunction ; Banknr11proef(reknr)
Have fun,
Jan Willem Teunisse,
Amersfoort
Hmm, the Tools plug-in already has a modulus10 check.
It would be easy to implement a modulus11 check.
When you want that please create a ticket in our support system: http://www.it2be.com/support/
(you need to register first when you are not yet registered)…
jw teunisse:
Michel,You also have to check if it’s a valid Dutch bankaccount number by performing the socalled 11-check.
I did the 11-check, that is why I needed to check the Result. The result is the som of the 11-check. I also exclude any non 0-9 enrty.
Here is the code:
var Getal = 9
var NieuweRekening = “”
var Result = 0
var Som = 0
if(forms.KlantenDetails.rekening != null && forms.KlantenDetails.rekening[0] != “P”)
{
for (var i = 0 ; i < forms.KlantenDetails.rekening.length ; i++)
{
if(forms.KlantenDetails.rekening >= 0 && forms.KlantenDetails.rekening <= 9)
* {*
Som = Som + forms.KlantenDetails.rekening_Getal_
_ Getal–
NieuweRekening = NieuweRekening + forms.KlantenDetails.rekening*
* }
}
forms.KlantenDetails.rekening = NieuweRekening*
* if(forms.KlantenDetails.rekening.length == 9)
{
Result = Som/11*
* var HeelGetal = parseInt(Result + “”);
if(Result == HeelGetal)
{
// Correct number*
* }
else*
* {
// Not correct*
* }
}
else*
//Check Giro…_
Here is a ready to use method you can call from anywhere.
// 'Elf Proef' method
// Method for checking if this is a valid (dutch) bankaccount number
var sBankNr = arguments[0],
nCheck = 0;
if ( sBankNr ) {
sBankNr = sBankNr.match(/\d/g).join(""); // clean up the string
if ( sBankNr.length != 9 ) {
return false;
} else {
for ( var i = 0 ; i<9 ; i++ )
{
nCheck += Number(sBankNr[i])*(9-i);
}
if ( nCheck%11 == 0 ) {
return true;
} else {
return false;
}
}
} else {
return false; // nothing was passed
}
Just pass the banknr as a string and it returns true or false if it’s valid.
Hope this helps.