16 releases (10 stable)

5.0.1 Oct 31, 2024
4.0.1 Dec 29, 2021
4.0.0 Jan 24, 2020
3.0.0 Nov 10, 2019
0.4.0 May 12, 2017

#60 in Parser implementations

Download history 20729/week @ 2024-07-19 24252/week @ 2024-07-26 23477/week @ 2024-08-02 22577/week @ 2024-08-09 23162/week @ 2024-08-16 31924/week @ 2024-08-23 37331/week @ 2024-08-30 38551/week @ 2024-09-06 31889/week @ 2024-09-13 33551/week @ 2024-09-20 34892/week @ 2024-09-27 28340/week @ 2024-10-04 30517/week @ 2024-10-11 38519/week @ 2024-10-18 37629/week @ 2024-10-25 94085/week @ 2024-11-01

206,445 downloads per month
Used in 8 crates (7 directly)

MIT/Apache

46KB
710 lines

iban_validate

Crates.io test Generation code fmt & clippy

This crate provides an easy way to validate an IBAN (International Bank Account Number). To do so, you can use the function parse(). This will check the IBAN rules as well as the BBAN structure. The provided Iban structure provides many methods to easy the handling of an IBAN. Many of these methods are provided via the IbanLike trait.

When BBAN parsing fails, the error type ParseIbanError provides useful information about what went wrong. Additionally, the error contains BaseIban, which can still be used to access useful information.

Example

The following example does a full validation of the IBAN and BBAN format.

use iban::*;

fn main() -> Result<(), ParseIbanError> {
  let account = "DE44500105175407324931".parse::<Iban>()?;
  assert_eq!(account.country_code(), "DE");
  assert_eq!(account.check_digits(), 44);
  assert_eq!(account.bban(), "500105175407324931");
  // The electronic format is also returned through `Debug::fmt`
  assert_eq!(account.electronic_str(), "DE44500105175407324931");
  // The pretty 'paper' format can be obtained via `Display::fmt`
  assert_eq!(account.to_string(), "DE44 5001 0517 5407 3249 31");
  assert_eq!(account.bank_identifier(), Some("50010517"));
  assert_eq!(account.branch_identifier(), None);
  Ok(())
}

What does this library provide?

  • A Iban type that can be used to parse account numbers very quickly. It doesn't require allocations at all, and instead leverages arrayvec under the hood.
  • A flexible API that is useful even when the country is not in the Swift registry (using BaseIban). Instead of using panic, the crate provides typed errors with what went wrong.
  • All functionality can be used in a no_std environment.
  • Optional serialization and deserialization via serde.
  • CI tested results via the Swift provided and custom test cases, as well as proptest.
  • #![forbid(unsafe_code)], making sure all code is written in safe Rust.

Usage

The crate can be found on crates.io. To use this crate, just add it as an dependency:

[dependencies]
iban_validate = "5"

Features

The following features can be used to configure the crate:

Contributing

If you experience issues with this crate or want to help, please look here.

Stability

This crate is usable on the latest stable release of the Rust compiler and adheres to semver. The IBAN registry may be updated with patch releases, because of this results may differ even between patch versions.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~230KB