Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBAN account number check #62

Closed
Autom3 opened this issue Feb 9, 2018 · 1 comment
Closed

IBAN account number check #62

Autom3 opened this issue Feb 9, 2018 · 1 comment

Comments

@Autom3
Copy link

Autom3 commented Feb 9, 2018

The iban module returns 'BE41091811735141' as a valid iban, whilst it is not, because it does not have a valid account number check (Using https://www.ibancalculator.com/iban_validieren.html as validator shows the error)

Here is a psuedo-code representation of how an account number should be checked:

Belgian IBAN number: BEkk BBBC CCCC CCxx (16 characters)

k = check digit for the entire IBAN
B = bank code
C = Account Number
x = check digit for the Account Number

Example: BE68 5390 0754 7034

ISO Country Code = BE (Belgium)
IBAN Check Digits = 68
BBAN = 5390 0754 7034 -> 12 characters, the usual BBAN format = 999-9999999-99
Bank Identifier = 539
Account Number = 0075470
Account Number check digits = 34 -> 2 digits MOD97

Check algorithm which is applied on the account number

The entered check digit (CD1) is the last two digits of the Account Number.

The calculated check digit (CD2) is derived by concatenating the first two sections of the Account Number and calculating the remainder on dividing this by 97. If the remainder is equal to '0', then the calculated check digit is taken to be '97'.

If the entered check digit (CD1) and calculated check digit (CD2) are equal, then the Account Number is valid, else the check has failed.

Additionally, if the entered check digit (that is, the last section) is '00', then the Account Number is invalid because the calculated check digit can never be '00' as per the 3rd point.

Example using Account Number '123-4567890-78':

The entered check digit (CD1) is '78'.
The concatenation of the first two sections gives '1234567890'.
Divide the result by '97'.
1234567890 / 97 = 12727504
Derive the remainder.
1234567890 - (12727504 * 97) = 2
Therefore CD2 = 2.
Here CD1 <> CD2, therefore the Account Number is not valid.
In this case, a valid Account Number would be '123-4567890-02'.

@arthurdejong
Copy link
Owner

python-stdnum only includes extra country-specific IBAN checks for a couple of countries because the check algorithms are not very well documented in all cases.
The extra check for Belgian IBANs was implemented in 56002fa. It also includes a check to see if the bank identifier refers to a registered bank.
Thanks for pointing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants