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
Ibantype guarantees validity at compile time. - Robust error handling: Know exactly why an IBAN is invalid.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Basic Validation
use validate;
// Valid German IBAN
assert!;
// With spaces (whitespace is ignored)
assert!;
// Invalid IBAN (bad checksum)
assert!;
Using the Iban Type
use Iban;
let iban = new.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
Error Handling
use ;
match validate
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
- Sanitize: Remove all whitespace characters.
- Country Check: Verify the country code is known.
- Length Check: Ensure the IBAN matches the expected length for the country.
- Character Check: Ensure all characters are alphanumeric.
- 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:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.