This crate provides an easy way to validate an IBAN (International Bank Account Number). To do
so, you can use the function parse()
. If you want to check whether the address has a valid
BBAN (Basic Bank Account Number), you can use validate_bban()
. It also contains some
helper methods to make handling an IBAN easier.
Example
The following example does a full validation of the IBAN and BBAN format.
# use iban::ParseIbanError;
# fn try_main() -> Result<(), ParseIbanError> {
use iban::Iban;
use iban::BbanResult;
let account = "DE44500105175407324931".parse::<Iban>()?;
assert_eq!(account.validate_bban(), BbanResult::Valid);
assert_eq!(account.get_country_code(), "DE");
assert_eq!(account.get_check_digits(), 44);
assert_eq!(account.get_bban(), "500105175407324931");
assert_eq!(account.format_electronic(), "DE44500105175407324931");
assert_eq!(account.format_print(), "DE44 5001 0517 5407 3249 31");
#
# Ok(())
# }
# fn main() {
# try_main().unwrap();
# }
#