Skip to main content

Crate iban_check

Crate iban_check 

Source
Expand description

A dependency-free IBAN (International Bank Account Number) validation library for Rust.

This crate validates IBANs according to the ISO 13616 standard. It performs the following checks:

  • Verifies the country code is known and registered.
  • Verifies the IBAN length matches the country’s specification.
  • Verifies all characters are valid alphanumeric characters.
  • Verifies the Mod-97-10 checksum.

§Quick Start

use iban_check::validate;

// Valid German IBAN
assert!(validate("DE89370400440532013000").is_ok());

// With spaces (whitespace is ignored)
assert!(validate("DE89 3704 0044 0532 0130 00").is_ok());

// Invalid IBAN (bad checksum)
assert!(validate("DE89370400440532013001").is_err());

§Using the Iban Type

For a type-safe way to represent validated IBANs:

use iban_check::Iban;

let iban = Iban::new("GB82WEST12345698765432").unwrap();
assert_eq!(iban.country_code(), "GB");
assert_eq!(iban.check_digits(), "82");
assert_eq!(iban.bban(), "WEST12345698765432");

§Supported Countries

This library supports all IBAN countries as of 2024, including: Germany (DE), United Kingdom (GB), France (FR), Switzerland (CH), Netherlands (NL), Belgium (BE), Austria (AT), and many more (73 countries total).

§Error Handling

Validation returns structured errors so you know exactly why an IBAN is invalid:

use iban_check::{validate, ValidationError};

match validate("XX89INVALID") {
    Err(ValidationError::InvalidCountryCode) => println!("Unknown country!"),
    Err(ValidationError::InvalidLength { expected, found }) => {
        println!("Wrong length: expected {}, found {}", expected, found)
    }
    Err(ValidationError::InvalidChecksum) => println!("Bad checksum!"),
    Ok(()) => println!("Valid IBAN"),
    _ => {}
}

Re-exports§

pub use error::ValidationError;
pub use validator::Iban;
pub use validator::validate;

Modules§

error
validator