1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! 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"),
//! _ => {}
//! }
//! ```
// Private module for country data
// Re-export public API
pub use ValidationError;
pub use Iban;
pub use validate;