Skip to main content

validate_iban

Function validate_iban 

Source
pub fn validate_iban(input: &str) -> ValidationOutcome
Expand description

Validates an IBAN (ISO 13616) using the MOD-97 checksum.

Accepts the canonical compact form (no spaces) as well as the space-delimited print form. Length bounds: 15–34 characters once whitespace is stripped.

§Algorithm

  1. Strip all ASCII whitespace; upper-case.
  2. Move the first 4 characters (country + check digits) to the end.
  3. Map letters A-Z → 10..=35.
  4. The resulting integer must be congruent to 1 mod 97.

Implemented without num-bigint by walking the digit string left to right, taking each modulo step incrementally — this keeps the crate dependency-free for the ISO validator.

§Examples

use ssg::seo::jsonld::iso20022::validate_iban;
assert!(validate_iban("GB29NWBK60161331926819").is_valid());
assert!(!validate_iban("GB29").is_valid());