Skip to main content

validate_iban

Function validate_iban 

Source
pub fn validate_iban(s: &str) -> Result<(), ValidationError>
Expand description

Validate an ISO 13616 IBAN (International Bank Account Number) via the mod-97 check. Strips spaces (the typical printed “GB82 WEST 1234 5698 7654 32” shape) before validating.

Format requirements:

  • 2-letter ISO country code (uppercase).
  • 2-digit check digits.
  • 1–30 additional ASCII alphanumeric chars.
  • Total length 5–34.

Algorithm:

  1. Move the first 4 chars to the end.
  2. Replace each letter with two digits: A=10, B=11, …, Z=35.
  3. Treat the result as a single integer; mod 97 must equal 1.

This catches typos before hitting the bank-rails verification API. Does NOT verify the account exists / has funds — only the payment provider can do that.

§Errors

ValidationError { code: "invalid_iban", ... }.