APK errors

How to check the Azerbaijan IBAN sample

There is one number on this page: AZ84NABZ00000000137010002944. It is the calculation sample in the Central Bank's rule. It is not an account. No money is sent to it.

The second line is that same sample with only the last digit changed. That is not an account either.

The sample is 28 characters. AZ is the country. The next two digits are the check. Then come four letters. The remaining 20 characters are the account place. If it is short, zeros are written at the front.

The check follows ISO 7064, MOD 97-10. The first four characters move to the end. A letter becomes a number: A is 10, Z is 35. The resulting number is divided by 97. If the remainder is 1, the check digits are right. This does not show that an account exists.

  • The code first prints 1. The sample's check digits are right.
  • The second number is 28. When the last character changes, the remainder is not 1. That is enough to catch a typo.
  • The four letters in the middle of the sample are part of the sample. They are not an address to pay anyone.
  • In your own program you can check your own number. Do not write that number on a page, in a chat, or into the sample.
  • Even if the remainder is 1, do not send a large amount without checking with the bank. The form can be right and the account can be closed.
NUMUNE = "AZ84NABZ00000000137010002944"
# Eyni nümunədir. Yalnız son rəqəm dəyişib. Hesab deyil.
POZUK = "AZ84NABZ00000000137010002945"

def qaliq(iban: str) -> int:
    metn = iban.replace(" ", "").upper()
    if not (len(metn) == 28 and metn.startswith("AZ")):
        raise ValueError("format")
    kecmis = metn[4:] + metn[:4]
    reqem = "".join(str(ord(h) - 55) if h.isalpha() else h for h in kecmis)
    return int(reqem) % 97

print(qaliq(NUMUNE))
print(qaliq(POZUK))

Related guides