Many countries put their own check digits inside the BBAN. Rust helpers verify, compute and repair them.
Iban::parse and verify check only the international check digits. A valid IBAN can still contain
an account number that fails its national check, so check it separately when it matters, for example
before you send a Belgian direct debit.
Verify
Iban::national_check() returns a NationalCheck:
| Value | Meaning |
|---|---|
Valid | The account passes the country's national check |
Invalid | The account fails it |
Unsupported | The country has no national check, or the standard says this account can't be checked |
use laravel_rust_iban::{Iban, NationalCheck, verify_national_checksum};
fn main() -> Result<(), laravel_rust_iban::Error> {
let iban = Iban::parse("BE68 5390 0754 7034")?;
assert_eq!(iban.national_check(), NationalCheck::Valid);
// The free function skips the international check digits.
assert_eq!(verify_national_checksum("BE00539007547034")?, NationalCheck::Valid);
Ok(())
}
verify_national_checksum still needs a registered country, the country's length and its BBAN
structure. An invalid structure returns the same Error as parsing.
Compute and fix
| Call | Returns |
|---|---|
find_national_checksum(input) | The national check digits the account should have |
set_national_checksum(input) | The electronic IBAN with the national check digits written in and the international check digits recalculated |
iban.with_national_check_digits() | The same, as a new Iban |
use laravel_rust_iban::{find_national_checksum, set_national_checksum};
fn main() -> Result<(), laravel_rust_iban::Error> {
assert_eq!(find_national_checksum("BE68539007547000")?, "34");
assert_eq!(set_national_checksum("BE00539007547000")?, "BE68539007547034");
Ok(())
}
Both return Error::UnsupportedNationalCheck for a registered country without a national algorithm
and for Slovakia. The Dutch finder returns that error because the 11-test has no explicit digit.
The Dutch setter recalculates the international pair when the account passes the 11-test.
Countries
The algorithms follow the ECBS Register of European Account Numbers (TR201 V3.23).
| Countries | Algorithm | Find and set |
|---|---|---|
Belgium (BE) | The last two digits are the first ten modulo 97. A remainder of 0 gives 97 | Yes |
Spain (ES) | Two Modulus 11 digits: one over bank and branch, one over the account number | Yes |
France (FR), Monaco (MC) | The RIB key: the whole BBAN, letters converted, is divisible by 97 | Yes |
Montenegro (ME), North Macedonia (MK), Portugal (PT), Serbia (RS), Slovenia (SI), Timor-Leste (TL) | ISO/IEC 7064 MOD 97-10 over the BBAN. The key is 02 to 98 | Yes |
Norway (NO) | Modulus 11 with weights 5, 4, 3, 2, 7, 6, 5, 4, 3, 2. An account whose check digit would be 10 is invalid | Yes |
Italy (IT), San Marino (SM) | The CIN letter at the start of the BBAN, from the odd and even position tables | Yes |
Netherlands (NL) | The 11-test over the ten-digit account number. Accounts that start with 000 are Unsupported | set only, when the account passes |
Slovakia (SK) | Modulus 11 over both the six-digit prefix and the ten-digit account number | No, verify only |
Every other registered country returns NationalCheck::Unsupported. The RIB check applies to France and Monaco.
North Macedonia permits letters in the registered BBAN. Such IBANs can pass international validation
and return NationalCheck::Unsupported for the numeric national check.
Belgium
A Belgian BBAN is a ten-digit number followed by two check digits: the number modulo 97, written as
two digits, or 97 when the remainder is 0.
use laravel_rust_iban::{Iban, NationalCheck, find_national_checksum, set_national_checksum};
fn main() -> Result<(), laravel_rust_iban::Error> {
// A remainder below 10 is still written as two digits.
assert_eq!(find_national_checksum("BE00000000000500")?, "05");
// A remainder of 0 gives 97.
assert_eq!(set_national_checksum("BE00000000009700")?, "BE54000000009797");
// The international check digits are right, the national ones are not.
let iban = Iban::parse("BE46000123456700")?;
assert_eq!(iban.national_check(), NationalCheck::Invalid);
Ok(())
}Where this differs from PHP
globalcitizen/php-iban gets several of these cases wrong. This package follows the published
algorithms instead. The README
lists each difference.
Norwegian BBANs with zeros in positions five and six use a legacy national calculation.
They can pass international validation and return NationalCheck::Unsupported.