SwissQrBill.IBAN (swiss_qr_bill v0.1.3)

Copy Markdown View Source

IBAN validation, formatting, and QR-IBAN detection for Swiss QR bills.

Only CH and LI IBANs are supported, as required by the SIX QR-bill standard.

Validation

iex> SwissQrBill.IBAN.validate("CH93 0076 2011 6238 5295 7")
{:ok, "CH9300762011623852957"}

iex> SwissQrBill.IBAN.validate("DE89 3704 0044 0532 0130 00")
{:error, :unsupported_country}

Formatting

iex> SwissQrBill.IBAN.format("CH9300762011623852957")
"CH93 0076 2011 6238 5295 7"

Summary

Functions

Formats an IBAN in groups of 4 characters separated by spaces.

Normalizes an IBAN by removing whitespace and converting to uppercase.

Returns true if the IBAN is a QR-IBAN.

Returns true if the IBAN is valid for Swiss QR bills.

Validates an IBAN string for use in Swiss QR bills.

Functions

format(iban)

@spec format(String.t()) :: String.t()

Formats an IBAN in groups of 4 characters separated by spaces.

iex> SwissQrBill.IBAN.format("CH9300762011623852957")
"CH93 0076 2011 6238 5295 7"

normalize(iban)

@spec normalize(String.t()) :: String.t()

Normalizes an IBAN by removing whitespace and converting to uppercase.

qr_iban?(iban)

@spec qr_iban?(String.t()) :: boolean()

Returns true if the IBAN is a QR-IBAN.

A QR-IBAN has an IID (Institution Identification, positions 5-9) in the range 30000-31999. QR-IBANs require the QRR reference type.

iex> SwissQrBill.IBAN.qr_iban?("CH4431999123000889012")
true

iex> SwissQrBill.IBAN.qr_iban?("CH9300762011623852957")
false

valid?(iban)

@spec valid?(String.t()) :: boolean()

Returns true if the IBAN is valid for Swiss QR bills.

validate(iban)

@spec validate(String.t()) :: {:ok, String.t()} | {:error, atom()}

Validates an IBAN string for use in Swiss QR bills.

Returns {:ok, normalized_iban} if valid, {:error, reason} otherwise.

Error reasons

  • :invalid_format - not a valid IBAN format (must be 2 letters + 2 digits + alphanumeric)
  • :unsupported_country - only CH and LI are supported
  • :invalid_length - wrong length (must be 21 for CH/LI)
  • :invalid_check_digits - mod-97 check digit verification failed
  • :invalid_bban - BBAN structure doesn't match expected pattern