iban-check 0.1.0

A dependency-free IBAN validation library for Rust.
Documentation
  • Coverage
  • 70%
    14 out of 20 items documented3 out of 9 items with examples
  • Size
  • Source code size: 34.91 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 487.03 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • danielundeutsch

iban-validator

A dependency-free Rust library for validating International Bank Account Numbers (IBAN) according to ISO 13616.

Features

  • Zero dependencies: No external crates required.
  • Fast and lightweight: Optimized for performance with zero allocations on the fast path.
  • Comprehensive: Supports all 73 registered IBAN countries.
  • Type-safe: Optional Iban type guarantees validity at compile time.
  • Robust error handling: Know exactly why an IBAN is invalid.

Installation

Add this to your Cargo.toml:

[dependencies]
iban-validator = "0.1.0"

Usage

Basic Validation

use iban_validator::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

use iban_validator::Iban;

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

Error Handling

use iban_validator::{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"),
    _ => {}
}

Supported Countries

All IBAN countries as of 2024 (73 total), including:

  • Germany (DE), United Kingdom (GB), France (FR), Switzerland (CH)
  • Netherlands (NL), Belgium (BE), Austria (AT), Ireland (IE)
  • And many more across Europe, Middle East, Africa, and the Americas.

Validation Logic

  1. Sanitize: Remove all whitespace characters.
  2. Country Check: Verify the country code is known.
  3. Length Check: Ensure the IBAN matches the expected length for the country.
  4. Character Check: Ensure all characters are alphanumeric.
  5. Checksum: Verify the Mod-97-10 checksum (move first 4 chars to end, convert letters to numbers, divide by 97, check remainder == 1).

License

This project is licensed under either of:

at your option.