insurello/elm-swedish-bank-account-number/2.0.0

NOTE: the latest version is 2.0.4

SwedishBankAccountNumber.ClearingNumber

Validating a bank account number is a two-step process: First you need to validate the clearing number. Why?

  • To know which bank the bank account number is for, and as such which validation rules to use.
  • Newer “type 1” accounts include the clearing number in the checksum calculation.

This module lets you validate clearing numbers.

type alias ClearingNumber =
ClearingNumberInternal

Represents a Swedish clearing number.

The only way to create a value of the ClearingNumber type is by calling fromString. This way, if you encounter a ClearingNumber, you know that it is always valid.

ClearingNumber also contains information about which Swedish bank the bank account number is for.

type Error
= BadLength Int
| Unknown

Trying to construct a ClearingNumber can fail in two ways:

  • The clearing number is too short or too long. BadLength contains how many digits were actually passed. Clearing numbers are always 4 or 5 digits long.
  • The clearing number is unknown.
= Standard
| DataclearingOnly
| Historical

Banks are categorized into three categories:

  • Standard: The bank is active, and part of both the Bankgiro and Data clearing systems.
  • DataclearingOnly: The bank is active, part of the Data clearing system, but not part of the Bankgiro system. They are marked with “(deltar endast i Dataclearingen, ej i Bankgirosystemet)” in Bankgirot’s PDF. (Bankgirot is a Swedish Clearing organization, while “Dataclearingen” is a transfer system owned by the Swedish Bankers’ Association.)
  • Historical: The bank does not exist anymore.
fromString : String -> Result Error ( Category, ClearingNumber )

Validate and construct a ClearingNumber.

The clearing number string is allowed to have any kind of crazy formatting. The function simply takes all the digits of the string and discards all other characters. The following all mean the same thing:

9420
94 20
94,20
abc94-2#0!

If you have a form field for the clearing number, you might want to normalize it on blur. You can use String.filter Char.isDigit myString to do so.

The function also returns the Category of the bank, to remind you to case on the different categories:

  • Standard: All is good to go!
  • DataclearingOnly: If your system only can make Bankgiro transfers, you might want to show an error message for this category.
  • Historical: You probably want to show a nice error message saying that the bank does not exist anymore.
toString : ClearingNumber -> String

Get a string containing digits only (no hyphens or spaces or anything), such as “9420”.

getBankName : ClearingNumber -> String

Get a human readable string name of the bank identified from the clearing number, such as “Länsförsäkringar Bank”.