Compare commits
13 Commits
368225f331
...
0.1.7.rc3
| Author | SHA1 | Date | |
|---|---|---|---|
| ce90960649 | |||
| e7e6bbda29 | |||
| 6ec94020ef | |||
| dc1b802c77 | |||
| 384b9b7a39 | |||
| 4abf01b752 | |||
| ae17d13731 | |||
| 4447a10bf2 | |||
| 51c5c1d800 | |||
| fdf28f7609 | |||
| 6b5f3676c8 | |||
| 390036bafb | |||
| 1a9d6758fd |
67
README.md
67
README.md
@@ -12,58 +12,66 @@ In just a few letters and numbers, the IBAN captures all of the country, bank, a
|
||||
|
||||
### Successfull case to parse IBAN
|
||||
|
||||
Parse string with valid formatted IBAN from supported country
|
||||
|
||||
```elixir
|
||||
{:ok, iban} = "FI2112345600000785" |> IbanEx.Parser.parse()
|
||||
IO.inspect(iban)
|
||||
IbanEx.Iban.pretty(iban)
|
||||
```
|
||||
|
||||
#### Response
|
||||
|
||||
%IbanEx.Iban{
|
||||
iex> "FI2112345600000785" |> IbanEx.Parser.parse()
|
||||
{:ok, %IbanEx.Iban{
|
||||
country_code: "FI",
|
||||
check_digits: "21",
|
||||
bank_code: "123456",
|
||||
branch_code: nil,
|
||||
national_check: "5",
|
||||
account_number: "0000078"
|
||||
}
|
||||
|
||||
"FI 21 123456 0000078 5"
|
||||
}}
|
||||
```
|
||||
|
||||
### Errors cases of IBAN parsing
|
||||
|
||||
Parse strings with invalid formatted IBANs from unsupported and supported countries
|
||||
#### To check IBAN's country is supported
|
||||
|
||||
```elixir
|
||||
{:error, unsupported_country_code} = "AZ21NABZ00000000137010001944" |> IbanEx.Parser.parse()
|
||||
IO.inspect(IbanEx.Error.message(unsupported_country_code), label: unsupported_country_code)
|
||||
|
||||
{:error, invalid_length_code} = "AT6119043002345732012" |> IbanEx.Parser.parse()
|
||||
IO.inspect(IbanEx.Error.message(invalid_length_code), label: invalid_length_code)
|
||||
|
||||
{:error, invalid_checksum} = "AT621904300234573201" |> IbanEx.Parser.parse()
|
||||
IO.inspect(IbanEx.Error.message(invalid_checksum), label: invalid_checksum)
|
||||
iex> {:error, unsupported_country_code} = IbanEx.Parser.parse("ZU21NABZ00000000137010001944")
|
||||
{:error, :unsupported_country_code}
|
||||
iex> IbanEx.Error.message(unsupported_country_code)
|
||||
"Unsupported country code"
|
||||
```
|
||||
|
||||
#### Response
|
||||
#### Validate and check IBAN length
|
||||
|
||||
unsupported_country_code: "Unsupported country code"
|
||||
invalid_length: "IBAN violates the required length"
|
||||
invalid_checksum: "IBAN's checksum is invalid"
|
||||
```elixir
|
||||
iex> {:error, invalid_length} = IbanEx.Parser.parse("AT6119043002345732012")
|
||||
{:error, :invalid_length}
|
||||
iex> IbanEx.Error.message(invalid_length)
|
||||
"IBAN violates the required length"
|
||||
```
|
||||
|
||||
```elixir
|
||||
iex> {:error, length_to_long} = IbanEx.Validator.check_iban_length("AT6119043002345732012")
|
||||
{:error, :length_to_long}
|
||||
iex> IbanEx.Error.message(length_to_long)
|
||||
"IBAN longer then required length"
|
||||
iex> {:error, length_to_short} = IbanEx.Validator.check_iban_length("AT61190430023457320")
|
||||
{:error, :length_to_short}
|
||||
iex> IbanEx.Error.message(length_to_short)
|
||||
"IBAN shorter then required length"
|
||||
```
|
||||
|
||||
#### Validate IBAN checksum
|
||||
|
||||
```elixir
|
||||
iex> {:error, invalid_checksum} = IbanEx.Parser.parse("AT621904300234573201")
|
||||
{:error, :invalid_checksum}
|
||||
iex> IbanEx.Error.message(invalid_checksum)
|
||||
"IBAN's checksum is invalid"
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
|
||||
by adding `iban_ex` to your list of dependencies in `mix.exs`:
|
||||
The package can be installed by adding `iban_ex` to your list of dependencies in `mix.exs`:
|
||||
|
||||
```elixir
|
||||
def deps do
|
||||
[
|
||||
{:iban_ex, "~> 0.1.0"}
|
||||
{:iban_ex, "~> 0.1.6"}
|
||||
]
|
||||
end
|
||||
```
|
||||
@@ -71,4 +79,3 @@ end
|
||||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
|
||||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
|
||||
be found at <https://hexdocs.pm/iban_ex>.
|
||||
|
||||
|
||||
56
TODO.md
Normal file
56
TODO.md
Normal file
@@ -0,0 +1,56 @@
|
||||
TODO Check Regexes and add unsupported now countries
|
||||
|
||||
```elixir
|
||||
"AA" => %{length: 16, rule: ~r/^[0-9A-Z]{12}$/i},
|
||||
"AO" => %{length: 25, rule: ~r/^[0-9]{21}$/i},
|
||||
"AX" => %{length: 18, rule: ~r/^[0-9]{14}$/i},
|
||||
"BF" => %{length: 27, rule: ~r/^[0-9]{23}$/i},
|
||||
"BI" => %{length: 16, rule: ~r/^[0-9]{12}$/i},
|
||||
"BJ" => %{length: 28, rule: ~r/^[A-Z]{1}[0-9]{23}$/i},
|
||||
"BL" => %{length: 27, rule: ~r/^[0-9]{10}[0-9A-Z]{11}[0-9]{2}$/i},
|
||||
"BY" => %{length: 28, rule: ~r/^[0-9A-Z]{4}[0-9]{4}[0-9A-Z]{16}$/i},
|
||||
"CF" => %{length: 27, rule: ~r/^[0-9]{23}$/i},
|
||||
"CG" => %{length: 27, rule: ~r/^[0-9]{23}$/i},
|
||||
"CI" => %{length: 28, rule: ~r/^[A-Z]{1}[0-9]{23}$/i},
|
||||
"CM" => %{length: 27, rule: ~r/^[0-9]{23}$/i},
|
||||
"CV" => %{length: 25, rule: ~r/^[0-9]{21}$/i},
|
||||
"DJ" => %{length: 27, rule: ~r/^[0-9]{23}$/i},
|
||||
"DZ" => %{length: 24, rule: ~r/^[0-9]{20}$/i},
|
||||
"GA" => %{length: 27, rule: ~r/^[0-9]{23}$/i},
|
||||
"GF" => %{length: 27, rule: ~r/^[0-9]{10}[0-9A-Z]{11}[0-9]{2}$/i},
|
||||
"GP" => %{length: 27, rule: ~r/^[0-9]{10}[0-9A-Z]{11}[0-9]{2}$/i},
|
||||
"GQ" => %{length: 27, rule: ~r/^[0-9]{23}$/i},
|
||||
"GW" => %{length: 25, rule: ~r/^[0-9A-Z]{2}[0-9]{19}$/i},
|
||||
"HN" => %{length: 28, rule: ~r/^[A-Z]{4}[0-9]{20}$/i},
|
||||
"IE" => %{length: 22, rule: ~r/^[A-Z]{4}[0-9]{14}$/i},
|
||||
"IQ" => %{length: 23, rule: ~r/^[0-9A-Z]{4}[0-9]{15}$/i},
|
||||
"IR" => %{length: 26, rule: ~r/^[0-9]{22}$/i},
|
||||
"IS" => %{length: 26, rule: ~r/^[0-9]{22}$/i},
|
||||
"KM" => %{length: 27, rule: ~r/^[0-9]{23}$/i},
|
||||
"LC" => %{length: 32, rule: ~r/^[A-Z]{4}[0-9A-Z]{24}$/i},
|
||||
"MA" => %{length: 28, rule: ~r/^[0-9]{24}$/i},
|
||||
"MF" => %{length: 27, rule: ~r/^[0-9]{10}[0-9A-Z]{11}[0-9]{2}$/i},
|
||||
"MG" => %{length: 27, rule: ~r/^[0-9]{23}$/i},
|
||||
"MK" => %{length: 19, rule: ~r/^[0-9]{3}[0-9A-Z]{10}[0-9]{2}$/i},
|
||||
"ML" => %{length: 28, rule: ~r/^[A-Z]{1}[0-9]{23}$/i},
|
||||
"MQ" => %{length: 27, rule: ~r/^[0-9]{10}[0-9A-Z]{11}[0-9]{2}$/i},
|
||||
"MU" => %{length: 30, rule: ~r/^[A-Z]{4}[0-9]{19}[A-Z]{3}$/i},
|
||||
"MZ" => %{length: 25, rule: ~r/^[0-9]{21}$/i},
|
||||
"NC" => %{length: 27, rule: ~r/^[0-9]{10}[0-9A-Z]{11}[0-9]{2}$/i},
|
||||
"NE" => %{length: 28, rule: ~r/^[A-Z]{2}[0-9]{22}$/i},
|
||||
"NI" => %{length: 32, rule: ~r/^[A-Z]{4}[0-9]{24}$/i},
|
||||
"PF" => %{length: 27, rule: ~r/^[0-9]{10}[0-9A-Z]{11}[0-9]{2}$/i},
|
||||
"PM" => %{length: 27, rule: ~r/^[0-9]{10}[0-9A-Z]{11}[0-9]{2}$/i},
|
||||
"PS" => %{length: 29, rule: ~r/^[A-Z]{4}[0-9A-Z]{21}$/i},
|
||||
"QA" => %{length: 29, rule: ~r/^[A-Z]{4}[0-9]{4}[0-9A-Z]{17}$/i},
|
||||
"RE" => %{length: 27, rule: ~r/^[0-9]{10}[0-9A-Z]{11}[0-9]{2}$/i},
|
||||
"SC" => %{length: 31, rule: ~r/^[A-Z]{4}[0-9]{20}[A-Z]{3}$/i},
|
||||
"SN" => %{length: 28, rule: ~r/^[A-Z]{1}[0-9]{23}$/i},
|
||||
"ST" => %{length: 25, rule: ~r/^[0-9]{8}[0-9]{13}$/i},
|
||||
"TD" => %{length: 27, rule: ~r/^[0-9]{23}$/i},
|
||||
"TF" => %{length: 27, rule: ~r/^[0-9]{10}[0-9A-Z]{11}[0-9]{2}$/i},
|
||||
"TG" => %{length: 28, rule: ~r/^[A-Z]{2}[0-9]{22}$/i},
|
||||
"TN" => %{length: 24, rule: ~r/^[0-9]{20}$/i},
|
||||
"WF" => %{length: 27, rule: ~r/^[0-9]{10}[0-9A-Z]{11}[0-9]{2}$/i},
|
||||
"YT" => %{length: 27, rule: ~r/^[0-9]{10}[0-9A-Z]{11}[0-9]{2}$/i}
|
||||
```
|
||||
@@ -1,4 +1,11 @@
|
||||
defmodule IbanEx.Commons do
|
||||
@moduledoc false
|
||||
|
||||
@spec blank(nil | binary()) :: nil | binary()
|
||||
def blank(nil), do: nil
|
||||
def blank(""), do: nil
|
||||
def blank(string) when is_binary(string), do: string
|
||||
|
||||
@spec normalize(binary()) :: binary()
|
||||
def normalize(string) do
|
||||
string
|
||||
@@ -12,5 +19,9 @@ def normalize_and_slice(string, range) do
|
||||
string
|
||||
|> normalize()
|
||||
|> String.slice(range)
|
||||
# |> case do
|
||||
# "" -> nil
|
||||
# result -> result
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,35 +1,84 @@
|
||||
defmodule IbanEx.Country do
|
||||
@moduledoc false
|
||||
|
||||
import IbanEx.Commons, only: [normalize: 1]
|
||||
|
||||
@type country_code() :: <<_::16>> | atom()
|
||||
@type error_tuple() :: {:error, atom()}
|
||||
|
||||
@supported_countries %{
|
||||
"AD" => IbanEx.Country.AD,
|
||||
"AE" => IbanEx.Country.AE,
|
||||
"AL" => IbanEx.Country.AL,
|
||||
"AT" => IbanEx.Country.AT,
|
||||
"AZ" => IbanEx.Country.AZ,
|
||||
"BA" => IbanEx.Country.BA,
|
||||
"BE" => IbanEx.Country.BE,
|
||||
"BG" => IbanEx.Country.BG,
|
||||
"BH" => IbanEx.Country.BH,
|
||||
"BR" => IbanEx.Country.BR,
|
||||
"CH" => IbanEx.Country.CH,
|
||||
"CR" => IbanEx.Country.CR,
|
||||
"CY" => IbanEx.Country.CY,
|
||||
"CZ" => IbanEx.Country.CZ,
|
||||
"DE" => IbanEx.Country.DE,
|
||||
"DO" => IbanEx.Country.DO,
|
||||
"DK" => IbanEx.Country.DK,
|
||||
"ES" => IbanEx.Country.ES,
|
||||
"EE" => IbanEx.Country.EE,
|
||||
"FR" => IbanEx.Country.FR,
|
||||
"ES" => IbanEx.Country.ES,
|
||||
"EG" => IbanEx.Country.EG,
|
||||
"FI" => IbanEx.Country.FI,
|
||||
"FR" => IbanEx.Country.FR,
|
||||
"FO" => IbanEx.Country.FO,
|
||||
"GB" => IbanEx.Country.GB,
|
||||
"GE" => IbanEx.Country.GE,
|
||||
"GI" => IbanEx.Country.GI,
|
||||
"GL" => IbanEx.Country.GL,
|
||||
"GR" => IbanEx.Country.GR,
|
||||
"GT" => IbanEx.Country.GT,
|
||||
"HR" => IbanEx.Country.HR,
|
||||
"HU" => IbanEx.Country.HU,
|
||||
"IE" => IbanEx.Country.IE,
|
||||
"IL" => IbanEx.Country.IL,
|
||||
"IT" => IbanEx.Country.IT,
|
||||
"JO" => IbanEx.Country.JO,
|
||||
"KZ" => IbanEx.Country.KZ,
|
||||
"KW" => IbanEx.Country.KW,
|
||||
"LB" => IbanEx.Country.LB,
|
||||
"LI" => IbanEx.Country.LI,
|
||||
"LT" => IbanEx.Country.LT,
|
||||
"LU" => IbanEx.Country.LU,
|
||||
"LV" => IbanEx.Country.LV,
|
||||
"MC" => IbanEx.Country.MC,
|
||||
"MD" => IbanEx.Country.MD,
|
||||
"ME" => IbanEx.Country.ME,
|
||||
"MK" => IbanEx.Country.MK,
|
||||
"MR" => IbanEx.Country.MR,
|
||||
"MT" => IbanEx.Country.MT,
|
||||
"NL" => IbanEx.Country.NL,
|
||||
"NO" => IbanEx.Country.NO,
|
||||
"PL" => IbanEx.Country.PL,
|
||||
"PT" => IbanEx.Country.PT,
|
||||
"UA" => IbanEx.Country.UA
|
||||
"PK" => IbanEx.Country.PK,
|
||||
"QA" => IbanEx.Country.QA,
|
||||
"RO" => IbanEx.Country.RO,
|
||||
"RS" => IbanEx.Country.RS,
|
||||
"SA" => IbanEx.Country.SA,
|
||||
"SE" => IbanEx.Country.SE,
|
||||
"SI" => IbanEx.Country.SI,
|
||||
"SK" => IbanEx.Country.SK,
|
||||
"SM" => IbanEx.Country.SM,
|
||||
"SV" => IbanEx.Country.SV,
|
||||
"TL" => IbanEx.Country.TL,
|
||||
"TR" => IbanEx.Country.TR,
|
||||
"UA" => IbanEx.Country.UA,
|
||||
"VA" => IbanEx.Country.VA,
|
||||
"VG" => IbanEx.Country.VG,
|
||||
"XK" => IbanEx.Country.XK
|
||||
}
|
||||
|
||||
@supported_country_codes Map.keys(@supported_countries)
|
||||
@supported_country_modules Map.values(@supported_countries)
|
||||
|
||||
@spec supported_countries() :: map()
|
||||
defp supported_countries(), do: @supported_countries
|
||||
@@ -37,7 +86,10 @@ defp supported_countries(), do: @supported_countries
|
||||
@spec supported_country_codes() :: [country_code()] | []
|
||||
def supported_country_codes(), do: @supported_country_codes
|
||||
|
||||
@spec country_module(country_code) :: Module.t() | error_tuple()
|
||||
@spec supported_country_modules() :: [module()] | []
|
||||
def supported_country_modules(), do: @supported_country_modules
|
||||
|
||||
@spec country_module(country_code) :: module() | error_tuple()
|
||||
def country_module(country_code) when is_binary(country_code) or is_atom(country_code) do
|
||||
normalized_country_code = normalize(country_code)
|
||||
case is_country_code_supported?(normalized_country_code) do
|
||||
|
||||
42
lib/iban_ex/country/ad.ex
Normal file
42
lib/iban_ex/country/ad.ex
Normal file
@@ -0,0 +1,42 @@
|
||||
defmodule IbanEx.Country.AD do
|
||||
@moduledoc """
|
||||
Andorra IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "AD",
|
||||
...> check_digits: "12",
|
||||
...> bank_code: "0001",
|
||||
...> branch_code: "2030",
|
||||
...> national_check: nil,
|
||||
...> account_number: "200359100100"
|
||||
...> }
|
||||
...> |> IbanEx.Country.AD.to_string()
|
||||
"AD 12 0001 2030 200359100100"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 24
|
||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<branch_code>[0-9]{4})(?<account_number>[0-9A-Z]{12})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
25
lib/iban_ex/country/ae.ex
Normal file
25
lib/iban_ex/country/ae.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.AE do
|
||||
@moduledoc """
|
||||
United Arab Emirates IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "AE",
|
||||
...> check_digits: "07",
|
||||
...> bank_code: "033",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "1234567890123456"
|
||||
...> }
|
||||
...> |> IbanEx.Country.AE.to_string()
|
||||
"AE 07 033 1234567890123456"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 23
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9]{16})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
42
lib/iban_ex/country/al.ex
Normal file
42
lib/iban_ex/country/al.ex
Normal file
@@ -0,0 +1,42 @@
|
||||
defmodule IbanEx.Country.AL do
|
||||
@moduledoc """
|
||||
Albania IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "AL",
|
||||
...> check_digits: "47",
|
||||
...> bank_code: "212",
|
||||
...> branch_code: "1100",
|
||||
...> national_check: "9",
|
||||
...> account_number: "0000000235698741"
|
||||
...> }
|
||||
...> |> IbanEx.Country.AL.to_string()
|
||||
"AL 47 212 1100 9 0000000235698741"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 28
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<branch_code>[0-9]{4})(?<national_check>[0-9]{1})(?<account_number>[0-9A-Z]{16})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, national_check, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
@@ -1,34 +1,25 @@
|
||||
defmodule IbanEx.Country.AT do
|
||||
@moduledoc """
|
||||
Austria IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "AT",
|
||||
...> check_digits: "61",
|
||||
...> bank_code: "19043",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "00234573201"
|
||||
...> }
|
||||
...> |> IbanEx.Country.AT.to_string()
|
||||
"AT 61 19043 00234573201"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 20
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{5})(?<account_number>[0-9]{11})$/i
|
||||
|
||||
@spec size() :: 20
|
||||
def size(), do: @size
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
|
||||
25
lib/iban_ex/country/az.ex
Normal file
25
lib/iban_ex/country/az.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.AZ do
|
||||
@moduledoc """
|
||||
Azerbaijan IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "AZ",
|
||||
...> check_digits: "21",
|
||||
...> bank_code: "NABZ",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "00000000137010001944"
|
||||
...> }
|
||||
...> |> IbanEx.Country.AZ.to_string()
|
||||
"AZ 21 NABZ 00000000137010001944"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 28
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9A-Z]{20})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
42
lib/iban_ex/country/ba.ex
Normal file
42
lib/iban_ex/country/ba.ex
Normal file
@@ -0,0 +1,42 @@
|
||||
defmodule IbanEx.Country.BA do
|
||||
@moduledoc """
|
||||
Bosnia and Herzegovina IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "BA",
|
||||
...> check_digits: "39",
|
||||
...> bank_code: "129",
|
||||
...> branch_code: "007",
|
||||
...> national_check: "94",
|
||||
...> account_number: "94010284"
|
||||
...> }
|
||||
...> |> IbanEx.Country.BA.to_string()
|
||||
"BA 39 129 007 94010284 94"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 20
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<branch_code>[0-9]{3})(?<account_number>[0-9]{8})(?<national_check>[0-9]{2})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, account_number, national_check]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
@@ -1,25 +1,32 @@
|
||||
defmodule IbanEx.Country.BE do
|
||||
@moduledoc """
|
||||
Belgium IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "BE",
|
||||
...> check_digits: "68",
|
||||
...> bank_code: "539",
|
||||
...> branch_code: nil,
|
||||
...> national_check: "34",
|
||||
...> account_number: "0075470"
|
||||
...> }
|
||||
...> |> IbanEx.Country.BE.to_string()
|
||||
"BE 68 539 0075470 34"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 16
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9]{7})(?<national_check>[0-9]{2})$/i
|
||||
|
||||
@spec size() :: 16
|
||||
def size(), do: @size
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
|
||||
@@ -1,25 +1,34 @@
|
||||
defmodule IbanEx.Country.BG do
|
||||
@moduledoc """
|
||||
Bulgaria IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "BG",
|
||||
...> check_digits: "80",
|
||||
...> bank_code: "BNBG",
|
||||
...> branch_code: "9661",
|
||||
...> national_check: nil,
|
||||
...> account_number: "1020345678"
|
||||
...> }
|
||||
...> |> IbanEx.Country.BG.to_string()
|
||||
"BG 80 BNBG 9661 1020345678"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 22
|
||||
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{4})(?<account_number>[0-9]{2}[0-9A-Z]{8})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@spec size() :: 22
|
||||
def size(), do: @size
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
|
||||
25
lib/iban_ex/country/bh.ex
Normal file
25
lib/iban_ex/country/bh.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.BH do
|
||||
@moduledoc """
|
||||
Bahrain IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "BH",
|
||||
...> check_digits: "67",
|
||||
...> bank_code: "BMAG",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "00001299123456"
|
||||
...> }
|
||||
...> |> IbanEx.Country.BH.to_string()
|
||||
"BH 67 BMAG 00001299123456"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 22
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9]{14})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
42
lib/iban_ex/country/br.ex
Normal file
42
lib/iban_ex/country/br.ex
Normal file
@@ -0,0 +1,42 @@
|
||||
defmodule IbanEx.Country.BR do
|
||||
@moduledoc """
|
||||
Brazil IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "BR",
|
||||
...> check_digits: "18",
|
||||
...> bank_code: "00360305",
|
||||
...> branch_code: "00001",
|
||||
...> account_number: "0009795493",
|
||||
...> national_check: "C1"
|
||||
...> }
|
||||
...> |> IbanEx.Country.BR.to_string()
|
||||
"BR 18 00360305 00001 0009795493 C1"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 29
|
||||
@rule ~r/^(?<bank_code>[0-9]{8})(?<branch_code>[0-9]{5})(?<account_number>[0-9]{10})(?<national_check>[A-Z]{1}[0-9A-Z]{1})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
account_number: account_number,
|
||||
national_check: national_check
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, account_number, national_check]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
@@ -1,34 +1,25 @@
|
||||
defmodule IbanEx.Country.CH do
|
||||
@moduledoc """
|
||||
Switzerland IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "CH",
|
||||
...> check_digits: "93",
|
||||
...> bank_code: "00762",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "011623852957"
|
||||
...> }
|
||||
...> |> IbanEx.Country.CH.to_string()
|
||||
"CH 93 00762 011623852957"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 21
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{5})(?<account_number>[0-9A-Z]{12})$/i
|
||||
|
||||
@spec size() :: 21
|
||||
def size(), do: @size
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
|
||||
25
lib/iban_ex/country/cr.ex
Normal file
25
lib/iban_ex/country/cr.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.CR do
|
||||
@moduledoc """
|
||||
Costa Rica IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "CR",
|
||||
...> check_digits: "05",
|
||||
...> bank_code: "0152",
|
||||
...> branch_code: nil,
|
||||
...> account_number: "02001026284066",
|
||||
...> national_check: nil
|
||||
...> }
|
||||
...> |> IbanEx.Country.CR.to_string()
|
||||
"CR 05 0152 02001026284066"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 22
|
||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{14})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
@@ -1,25 +1,32 @@
|
||||
defmodule IbanEx.Country.CY do
|
||||
@moduledoc """
|
||||
Cyprus IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "CY",
|
||||
...> check_digits: "17",
|
||||
...> bank_code: "002",
|
||||
...> branch_code: "00128",
|
||||
...> national_check: nil,
|
||||
...> account_number: "0000001200527600"
|
||||
...> }
|
||||
...> |> IbanEx.Country.CY.to_string()
|
||||
"CY 17 002 00128 0000001200527600"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 28
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{16})$/i
|
||||
|
||||
@spec size() :: 28
|
||||
def size(), do: @size
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
|
||||
@@ -1,36 +1,25 @@
|
||||
defmodule IbanEx.Country.CZ do
|
||||
@moduledoc """
|
||||
Czech Republic IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "CZ",
|
||||
...> check_digits: "65",
|
||||
...> bank_code: "0800",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "0000192000145399"
|
||||
...> }
|
||||
...> |> IbanEx.Country.CZ.to_string()
|
||||
"CZ 65 0800 0000192000145399"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 24
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{16})$/i
|
||||
|
||||
@spec size() :: 24
|
||||
def size(), do: @size
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
|
||||
@@ -1,36 +1,25 @@
|
||||
defmodule IbanEx.Country.DE do
|
||||
@moduledoc """
|
||||
Germany IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "DE",
|
||||
...> check_digits: "89",
|
||||
...> bank_code: "37040044",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "0532013000"
|
||||
...> }
|
||||
...> |> IbanEx.Country.DE.to_string()
|
||||
"DE 89 37040044 0532013000"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 22
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{8})(?<account_number>[0-9]{10})$/i
|
||||
|
||||
@spec size() :: 22
|
||||
def size(), do: @size
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
|
||||
@@ -1,36 +1,24 @@
|
||||
defmodule IbanEx.Country.DK do
|
||||
@moduledoc """
|
||||
Denmark IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "DK",
|
||||
...> check_digits: "50",
|
||||
...> bank_code: "0040",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "0440116243"
|
||||
...> }
|
||||
...> |> IbanEx.Country.DK.to_string()
|
||||
"DK 50 0040 0440116243"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 18
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{10})$/i
|
||||
|
||||
@spec size() :: 18
|
||||
def size(), do: @size
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
|
||||
25
lib/iban_ex/country/do.ex
Normal file
25
lib/iban_ex/country/do.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.DO do
|
||||
@moduledoc """
|
||||
Dominican Republic IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "DO",
|
||||
...> check_digits: "28",
|
||||
...> bank_code: "BAGR",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "00000001212453611324"
|
||||
...> }
|
||||
...> |> IbanEx.Country.DO.to_string()
|
||||
"DO 28 BAGR 00000001212453611324"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 28
|
||||
@rule ~r/^(?<bank_code>[0-9A-Z]{4})(?<account_number>[0-9]{20})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
@@ -1,25 +1,32 @@
|
||||
defmodule IbanEx.Country.EE do
|
||||
@moduledoc """
|
||||
Estonian IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "EE",
|
||||
...> check_digits: "38",
|
||||
...> bank_code: "22",
|
||||
...> branch_code: "00",
|
||||
...> national_check: "5",
|
||||
...> account_number: "22102014568"
|
||||
...> }
|
||||
...> |> IbanEx.Country.EE.to_string()
|
||||
"EE 38 22 00 22102014568 5"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 20
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{2})(?<branch_code>[0-9]{2})(?<account_number>[0-9]{11})(?<national_check>[0-9]{1})$/i
|
||||
|
||||
@spec size() :: 20
|
||||
def size(), do: @size
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
|
||||
42
lib/iban_ex/country/eg.ex
Normal file
42
lib/iban_ex/country/eg.ex
Normal file
@@ -0,0 +1,42 @@
|
||||
defmodule IbanEx.Country.EG do
|
||||
@moduledoc """
|
||||
Egypt IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "EG",
|
||||
...> check_digits: "38",
|
||||
...> bank_code: "0019",
|
||||
...> branch_code: "0005",
|
||||
...> national_check: nil,
|
||||
...> account_number: "00000000263180002"
|
||||
...> }
|
||||
...> |> IbanEx.Country.EG.to_string()
|
||||
"EG 38 0019 0005 00000000263180002"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 29
|
||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<branch_code>[0-9]{4})(?<account_number>[0-9]{17})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
@@ -1,25 +1,32 @@
|
||||
defmodule IbanEx.Country.ES do
|
||||
@moduledoc """
|
||||
Spain IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "ES",
|
||||
...> check_digits: "91",
|
||||
...> bank_code: "2100",
|
||||
...> branch_code: "0418",
|
||||
...> national_check: "45",
|
||||
...> account_number: "0200051332"
|
||||
...> }
|
||||
...> |> IbanEx.Country.ES.to_string()
|
||||
"ES 91 2100 0418 45 0200051332"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 24
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<branch_code>[0-9]{4})(?<national_check>[0-9]{2})(?<account_number>[0-9]{10})$/i
|
||||
|
||||
@spec size() :: 24
|
||||
def size(), do: @size
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
|
||||
@@ -1,25 +1,32 @@
|
||||
defmodule IbanEx.Country.FI do
|
||||
@moduledoc """
|
||||
Finland IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "FI",
|
||||
...> check_digits: "21",
|
||||
...> bank_code: "123456",
|
||||
...> branch_code: nil,
|
||||
...> national_check: "5",
|
||||
...> account_number: "0000078"
|
||||
...> }
|
||||
...> |> IbanEx.Country.FI.to_string()
|
||||
"FI 21 123456 0000078 5"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 18
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{6})(?<account_number>[0-9]{7})(?<national_check>[0-9]{1})$/i
|
||||
|
||||
@spec size() :: 18
|
||||
def size(), do: @size
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
|
||||
43
lib/iban_ex/country/fo.ex
Normal file
43
lib/iban_ex/country/fo.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.FO do
|
||||
@moduledoc """
|
||||
Faroe Islands IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "FO",
|
||||
...> check_digits: "62",
|
||||
...> bank_code: "6460",
|
||||
...> branch_code: nil,
|
||||
...> national_check: "4",
|
||||
...> account_number: "000163163"
|
||||
...> }
|
||||
...> |> IbanEx.Country.FO.to_string()
|
||||
"FO 62 6460 000163163 4"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 18
|
||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{9})(?<national_check>[0-9]{1})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number, national_check]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
@@ -1,25 +1,32 @@
|
||||
defmodule IbanEx.Country.FR do
|
||||
@moduledoc """
|
||||
France IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "FR",
|
||||
...> check_digits: "14",
|
||||
...> bank_code: "20041",
|
||||
...> branch_code: "01005",
|
||||
...> national_check: "06",
|
||||
...> account_number: "0500013M026"
|
||||
...> }
|
||||
...> |> IbanEx.Country.FR.to_string()
|
||||
"FR 14 20041 01005 0500013M026 06"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 27
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{5})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{11})(?<national_check>[0-9]{2})$/i
|
||||
|
||||
@spec size() :: 27
|
||||
def size(), do: @size
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
|
||||
@@ -1,25 +1,32 @@
|
||||
defmodule IbanEx.Country.GB do
|
||||
@moduledoc """
|
||||
United Kingdom IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "GB",
|
||||
...> check_digits: "29",
|
||||
...> bank_code: "NWBK",
|
||||
...> branch_code: "601613",
|
||||
...> national_check: "06",
|
||||
...> account_number: "31926819"
|
||||
...> }
|
||||
...> |> IbanEx.Country.GB.to_string()
|
||||
"GB 29 NWBK 601613 31926819"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 22
|
||||
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{6})(?<account_number>[0-9]{8})$/i
|
||||
|
||||
@spec size() :: 22
|
||||
def size(), do: @size
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
|
||||
25
lib/iban_ex/country/ge.ex
Normal file
25
lib/iban_ex/country/ge.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.GE do
|
||||
@moduledoc """
|
||||
Georgia IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "GE",
|
||||
...> check_digits: "29",
|
||||
...> bank_code: "NB",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "0000000101904917"
|
||||
...> }
|
||||
...> |> IbanEx.Country.GE.to_string()
|
||||
"GE 29 NB 0000000101904917"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 22
|
||||
@rule ~r/^(?<bank_code>[A-Z]{2})(?<account_number>[0-9]{16})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
25
lib/iban_ex/country/gi.ex
Normal file
25
lib/iban_ex/country/gi.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.GI do
|
||||
@moduledoc """
|
||||
Gibraltar IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "GI",
|
||||
...> check_digits: "75",
|
||||
...> bank_code: "NWBK",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "000000007099453"
|
||||
...> }
|
||||
...> |> IbanEx.Country.GI.to_string()
|
||||
"GI 75 NWBK 000000007099453"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 23
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9A-Z]{15})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
25
lib/iban_ex/country/gl.ex
Normal file
25
lib/iban_ex/country/gl.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.GL do
|
||||
@moduledoc """
|
||||
Greenland IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "GL",
|
||||
...> check_digits: "89",
|
||||
...> bank_code: "6471",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "0001000206"
|
||||
...> }
|
||||
...> |> IbanEx.Country.GL.to_string()
|
||||
"GL 89 6471 0001000206"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 18
|
||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{10})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
43
lib/iban_ex/country/gr.ex
Normal file
43
lib/iban_ex/country/gr.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.GR do
|
||||
@moduledoc """
|
||||
Greece IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "GR",
|
||||
...> check_digits: "16",
|
||||
...> bank_code: "011",
|
||||
...> branch_code: "0125",
|
||||
...> national_check: nil,
|
||||
...> account_number: "0000000012300695"
|
||||
...> }
|
||||
...> |> IbanEx.Country.GR.to_string()
|
||||
"GR 16 011 0125 0000000012300695"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 27
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<branch_code>[0-9]{4})(?<account_number>[0-9A-Z]{16})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
25
lib/iban_ex/country/gt.ex
Normal file
25
lib/iban_ex/country/gt.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.GT do
|
||||
@moduledoc """
|
||||
Guatemala IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "GT",
|
||||
...> check_digits: "82",
|
||||
...> bank_code: "TRAJ",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "01020000001210029690"
|
||||
...> }
|
||||
...> |> IbanEx.Country.GT.to_string()
|
||||
"GT 82 TRAJ 01020000001210029690"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 28
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9]{20})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
@@ -1,36 +1,25 @@
|
||||
defmodule IbanEx.Country.HR do
|
||||
@moduledoc """
|
||||
Croatia IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "HR",
|
||||
...> check_digits: "12",
|
||||
...> bank_code: "1001005",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "1863000160"
|
||||
...> }
|
||||
...> |> IbanEx.Country.HR.to_string()
|
||||
"HR 12 1001005 1863000160"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 21
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{7})(?<account_number>[0-9]{10})$/i
|
||||
|
||||
@spec size() :: 21
|
||||
def size(), do: @size
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
|
||||
43
lib/iban_ex/country/hu.ex
Normal file
43
lib/iban_ex/country/hu.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.HU do
|
||||
@moduledoc """
|
||||
Hungary IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "HU",
|
||||
...> check_digits: "42",
|
||||
...> bank_code: "117",
|
||||
...> branch_code: "7301",
|
||||
...> national_check: "0",
|
||||
...> account_number: "6111110180000000"
|
||||
...> }
|
||||
...> |> IbanEx.Country.HU.to_string()
|
||||
"HU 42 117 7301 6111110180000000 0"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 28
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<branch_code>[0-9]{4})(?<account_number>[0-9]{16})(?<national_check>[0-9]{1})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, account_number, national_check]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
43
lib/iban_ex/country/ie.ex
Normal file
43
lib/iban_ex/country/ie.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.IE do
|
||||
@moduledoc """
|
||||
Ireland IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "IE",
|
||||
...> check_digits: "29",
|
||||
...> bank_code: "AIBK",
|
||||
...> branch_code: "931152",
|
||||
...> national_check: nil,
|
||||
...> account_number: "12345678"
|
||||
...> }
|
||||
...> |> IbanEx.Country.IE.to_string()
|
||||
"IE 29 AIBK 931152 12345678"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 22
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{6})(?<account_number>[0-9]{8})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
42
lib/iban_ex/country/il.ex
Normal file
42
lib/iban_ex/country/il.ex
Normal file
@@ -0,0 +1,42 @@
|
||||
defmodule IbanEx.Country.IL do
|
||||
@moduledoc """
|
||||
Israel IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "IL",
|
||||
...> check_digits: "62",
|
||||
...> bank_code: "010",
|
||||
...> branch_code: "800",
|
||||
...> national_check: nil,
|
||||
...> account_number: "0000099999999"
|
||||
...> }
|
||||
...> |> IbanEx.Country.IL.to_string()
|
||||
"IL 62 010 800 0000099999999"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 23
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<branch_code>[0-9]{3})(?<account_number>[0-9]{13})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
43
lib/iban_ex/country/it.ex
Normal file
43
lib/iban_ex/country/it.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.IT do
|
||||
@moduledoc """
|
||||
Italy IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "IT",
|
||||
...> check_digits: "60",
|
||||
...> bank_code: "05428",
|
||||
...> branch_code: "11101",
|
||||
...> national_check: "X",
|
||||
...> account_number: "000000123456"
|
||||
...> }
|
||||
...> |> IbanEx.Country.IT.to_string()
|
||||
"IT 60 X 05428 11101 000000123456"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 27
|
||||
@rule ~r/^(?<national_check>[A-Z]{1})(?<bank_code>[0-9]{5})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{12})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, national_check, bank_code, branch_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
42
lib/iban_ex/country/jo.ex
Normal file
42
lib/iban_ex/country/jo.ex
Normal file
@@ -0,0 +1,42 @@
|
||||
defmodule IbanEx.Country.JO do
|
||||
@moduledoc """
|
||||
Jordan IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "JO",
|
||||
...> check_digits: "94",
|
||||
...> bank_code: "CBJO",
|
||||
...> branch_code: "0010",
|
||||
...> national_check: nil,
|
||||
...> account_number: "000000000131000302"
|
||||
...> }
|
||||
...> |> IbanEx.Country.JO.to_string()
|
||||
"JO 94 CBJO 0010 000000000131000302"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 30
|
||||
@rule ~r/^(?<bank_code>[A-Z0-9]{4})(?<branch_code>[0-9]{4})(?<account_number>[A-Z0-9]{18})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
25
lib/iban_ex/country/kw.ex
Normal file
25
lib/iban_ex/country/kw.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.KW do
|
||||
@moduledoc """
|
||||
Kuwait IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "KW",
|
||||
...> check_digits: "81",
|
||||
...> bank_code: "CBKU",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "0000000000001234560101"
|
||||
...> }
|
||||
...> |> IbanEx.Country.KW.to_string()
|
||||
"KW 81 CBKU 0000000000001234560101"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 30
|
||||
@rule ~r/^(?<bank_code>[A-Z0-9]{4})(?<account_number>[0-9]{22})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
25
lib/iban_ex/country/kz.ex
Normal file
25
lib/iban_ex/country/kz.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.KZ do
|
||||
@moduledoc """
|
||||
Kazakhstan IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "KZ",
|
||||
...> check_digits: "86",
|
||||
...> bank_code: "125",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "KZT5004100100"
|
||||
...> }
|
||||
...> |> IbanEx.Country.KZ.to_string()
|
||||
"KZ 86 125 KZT5004100100"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 20
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[A-Z0-9]{13})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
25
lib/iban_ex/country/lb.ex
Normal file
25
lib/iban_ex/country/lb.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.LB do
|
||||
@moduledoc """
|
||||
Lebanon IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "LB",
|
||||
...> check_digits: "62",
|
||||
...> bank_code: "0999",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "00000001001901229114"
|
||||
...> }
|
||||
...> |> IbanEx.Country.LB.to_string()
|
||||
"LB 62 0999 00000001001901229114"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 28
|
||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{20})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
25
lib/iban_ex/country/li.ex
Normal file
25
lib/iban_ex/country/li.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.LI do
|
||||
@moduledoc """
|
||||
Liechtenstein IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "LI",
|
||||
...> check_digits: "21",
|
||||
...> bank_code: "08810",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "0002324013AA"
|
||||
...> }
|
||||
...> |> IbanEx.Country.LI.to_string()
|
||||
"LI 21 08810 0002324013AA"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 21
|
||||
@rule ~r/^(?<bank_code>[0-9]{5})(?<account_number>[0-9A-Z]{12})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
@@ -1,36 +1,25 @@
|
||||
defmodule IbanEx.Country.LT do
|
||||
@moduledoc """
|
||||
Lithuanian IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "LT",
|
||||
...> check_digits: "12",
|
||||
...> bank_code: "10000",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "11101001000"
|
||||
...> }
|
||||
...> |> IbanEx.Country.LT.to_string()
|
||||
"LT 12 10000 11101001000"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 20
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{5})(?<account_number>[0-9]{11})$/i
|
||||
|
||||
@spec size() :: 20
|
||||
def size(), do: @size
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
|
||||
@@ -1,36 +1,25 @@
|
||||
defmodule IbanEx.Country.LU do
|
||||
@moduledoc """
|
||||
Luxembourg IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "LU",
|
||||
...> check_digits: "28",
|
||||
...> bank_code: "001",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "9400644750000"
|
||||
...> }
|
||||
...> |> IbanEx.Country.LU.to_string()
|
||||
"LU 28 001 9400644750000"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 20
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9A-Z]{13})$/i
|
||||
|
||||
@spec size() :: 20
|
||||
def size(), do: @size
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
|
||||
@@ -1,36 +1,25 @@
|
||||
defmodule IbanEx.Country.LV do
|
||||
@moduledoc """
|
||||
Latvian IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "LV",
|
||||
...> check_digits: "80",
|
||||
...> bank_code: "BANK",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "0000435195001"
|
||||
...> }
|
||||
...> |> IbanEx.Country.LV.to_string()
|
||||
"LV 80 BANK 0000435195001"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 21
|
||||
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9A-Z]{13})$/i
|
||||
|
||||
@spec size() :: 21
|
||||
def size(), do: @size
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
|
||||
43
lib/iban_ex/country/mc.ex
Normal file
43
lib/iban_ex/country/mc.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.MC do
|
||||
@moduledoc """
|
||||
Monaco IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "MC",
|
||||
...> check_digits: "58",
|
||||
...> bank_code: "11222",
|
||||
...> branch_code: "00001",
|
||||
...> national_check: "30",
|
||||
...> account_number: "01234567890"
|
||||
...> }
|
||||
...> |> IbanEx.Country.MC.to_string()
|
||||
"MC 58 11222 00001 01234567890 30"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 27
|
||||
@rule ~r/^(?<bank_code>[0-9]{5})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{11})(?<national_check>[0-9]{2})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, account_number, national_check]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
25
lib/iban_ex/country/md.ex
Normal file
25
lib/iban_ex/country/md.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.MD do
|
||||
@moduledoc """
|
||||
Republic of Moldova IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "MD",
|
||||
...> check_digits: "24",
|
||||
...> bank_code: "AG",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "000225100013104168"
|
||||
...> }
|
||||
...> |> IbanEx.Country.MD.to_string()
|
||||
"MD 24 AG 000225100013104168"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 24
|
||||
@rule ~r/^(?<bank_code>[A-Z]{2})(?<account_number>[0-9]{18})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
43
lib/iban_ex/country/me.ex
Normal file
43
lib/iban_ex/country/me.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.ME do
|
||||
@moduledoc """
|
||||
Montenegro IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "ME",
|
||||
...> check_digits: "25",
|
||||
...> bank_code: "505",
|
||||
...> branch_code: nil,
|
||||
...> national_check: "51",
|
||||
...> account_number: "0000123456789"
|
||||
...> }
|
||||
...> |> IbanEx.Country.ME.to_string()
|
||||
"ME 25 505 0000123456789 51"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 22
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9]{13})(?<national_check>[0-9]{2})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number, national_check]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
43
lib/iban_ex/country/mk.ex
Normal file
43
lib/iban_ex/country/mk.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.MK do
|
||||
@moduledoc """
|
||||
Macedonia IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "MK",
|
||||
...> check_digits: "07",
|
||||
...> bank_code: "250",
|
||||
...> branch_code: nil,
|
||||
...> national_check: "84",
|
||||
...> account_number: "1200000589"
|
||||
...> }
|
||||
...> |> IbanEx.Country.MK.to_string()
|
||||
"MK 07 250 1200000589 84"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 19
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9]{10})(?<national_check>[0-9]{2})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number, national_check]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
43
lib/iban_ex/country/mr.ex
Normal file
43
lib/iban_ex/country/mr.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.MR do
|
||||
@moduledoc """
|
||||
Mauritania IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "MR",
|
||||
...> check_digits: "13",
|
||||
...> bank_code: "00020",
|
||||
...> branch_code: "00101",
|
||||
...> national_check: "53",
|
||||
...> account_number: "00001234567"
|
||||
...> }
|
||||
...> |> IbanEx.Country.MR.to_string()
|
||||
"MR 13 00020 00101 00001234567 53"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 27
|
||||
@rule ~r/^(?<bank_code>[0-9]{5})(?<branch_code>[0-9]{5})(?<account_number>[0-9]{11})(?<national_check>[0-9]{2})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, account_number, national_check]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
@@ -1,25 +1,32 @@
|
||||
defmodule IbanEx.Country.MT do
|
||||
@moduledoc """
|
||||
Malta IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "MT",
|
||||
...> check_digits: "84",
|
||||
...> bank_code: "MALT",
|
||||
...> branch_code: "01100",
|
||||
...> national_check: nil,
|
||||
...> account_number: "0012345MTLCAST001S"
|
||||
...> }
|
||||
...> |> IbanEx.Country.MT.to_string()
|
||||
"MT 84 MALT 01100 0012345MTLCAST001S"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 31
|
||||
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{18})$/i
|
||||
|
||||
@spec size() :: 31
|
||||
def size(), do: @size
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
|
||||
@@ -1,36 +1,25 @@
|
||||
defmodule IbanEx.Country.NL do
|
||||
@moduledoc """
|
||||
Netherlands IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "NL",
|
||||
...> check_digits: "91",
|
||||
...> bank_code: "ABNA",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "0417164300"
|
||||
...> }
|
||||
...> |> IbanEx.Country.NL.to_string()
|
||||
"NL 91 ABNA 0417164300"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 18
|
||||
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9]{10})$/i
|
||||
|
||||
@spec size() :: 18
|
||||
def size(), do: @size
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
|
||||
43
lib/iban_ex/country/no.ex
Normal file
43
lib/iban_ex/country/no.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.NO do
|
||||
@moduledoc """
|
||||
Norway IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "NO",
|
||||
...> check_digits: "93",
|
||||
...> bank_code: "8601",
|
||||
...> branch_code: nil,
|
||||
...> national_check: "7",
|
||||
...> account_number: "111794"
|
||||
...> }
|
||||
...> |> IbanEx.Country.NO.to_string()
|
||||
"NO 93 8601 111794 7"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 15
|
||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{6})(?<national_check>[0-9]{1})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number, national_check]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
25
lib/iban_ex/country/pk.ex
Normal file
25
lib/iban_ex/country/pk.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.PK do
|
||||
@moduledoc """
|
||||
Pakistan IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "PK",
|
||||
...> check_digits: "36",
|
||||
...> bank_code: "SCBL",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "0000001123456702"
|
||||
...> }
|
||||
...> |> IbanEx.Country.PK.to_string()
|
||||
"PK 36 SCBL 0000001123456702"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 24
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9]{16})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
@@ -1,25 +1,32 @@
|
||||
defmodule IbanEx.Country.PL do
|
||||
@moduledoc """
|
||||
Poland IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "PL",
|
||||
...> check_digits: "61",
|
||||
...> bank_code: "109",
|
||||
...> branch_code: "0101",
|
||||
...> national_check: "4",
|
||||
...> account_number: "0000071219812874"
|
||||
...> }
|
||||
...> |> IbanEx.Country.PL.to_string()
|
||||
"PL 61 109 0101 4 0000071219812874"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 28
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<branch_code>[0-9]{4})(?<national_check>[0-9]{1})(?<account_number>[0-9]{16})$/i
|
||||
|
||||
@spec size() :: 28
|
||||
def size(), do: @size
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
|
||||
@@ -1,25 +1,32 @@
|
||||
defmodule IbanEx.Country.PT do
|
||||
@moduledoc """
|
||||
Portugal IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "PT",
|
||||
...> check_digits: "50",
|
||||
...> bank_code: "0002",
|
||||
...> branch_code: "0123",
|
||||
...> national_check: "54",
|
||||
...> account_number: "12345678901"
|
||||
...> }
|
||||
...> |> IbanEx.Country.PT.to_string()
|
||||
"PT 50 0002 0123 12345678901 54"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 25
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<branch_code>[0-9]{4})(?<account_number>[0-9]{11})(?<national_check>[0-9]{2})$/i
|
||||
|
||||
@spec size() :: 25
|
||||
def size(), do: @size
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
|
||||
25
lib/iban_ex/country/qa.ex
Normal file
25
lib/iban_ex/country/qa.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.QA do
|
||||
@moduledoc """
|
||||
Qatar IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "QA",
|
||||
...> check_digits: "58",
|
||||
...> bank_code: "DOHB",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "00001234567890ABCDEFG"
|
||||
...> }
|
||||
...> |> IbanEx.Country.QA.to_string()
|
||||
"QA 58 DOHB 00001234567890ABCDEFG"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 29
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[A-Z0-9]{21})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
25
lib/iban_ex/country/ro.ex
Normal file
25
lib/iban_ex/country/ro.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.RO do
|
||||
@moduledoc """
|
||||
Romania IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "RO",
|
||||
...> check_digits: "49",
|
||||
...> bank_code: "AAAA",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "1B31007593840000"
|
||||
...> }
|
||||
...> |> IbanEx.Country.RO.to_string()
|
||||
"RO 49 AAAA 1B31007593840000"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 24
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9A-Z]{16})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
43
lib/iban_ex/country/rs.ex
Normal file
43
lib/iban_ex/country/rs.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.RS do
|
||||
@moduledoc """
|
||||
Serbia IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "RS",
|
||||
...> check_digits: "35",
|
||||
...> bank_code: "260",
|
||||
...> branch_code: nil,
|
||||
...> national_check: "79",
|
||||
...> account_number: "0056010016113"
|
||||
...> }
|
||||
...> |> IbanEx.Country.RS.to_string()
|
||||
"RS 35 260 0056010016113 79"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 22
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9]{13})(?<national_check>[0-9]{2})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number, national_check]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
25
lib/iban_ex/country/sa.ex
Normal file
25
lib/iban_ex/country/sa.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.SA do
|
||||
@moduledoc """
|
||||
Saudi Arabia IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "SA",
|
||||
...> check_digits: "03",
|
||||
...> bank_code: "80",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "000000608010167519"
|
||||
...> }
|
||||
...> |> IbanEx.Country.SA.to_string()
|
||||
"SA 03 80 000000608010167519"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 24
|
||||
@rule ~r/^(?<bank_code>[0-9]{2})(?<account_number>[0-9]{18})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
25
lib/iban_ex/country/se.ex
Normal file
25
lib/iban_ex/country/se.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.SE do
|
||||
@moduledoc """
|
||||
Sweden IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "SE",
|
||||
...> check_digits: "45",
|
||||
...> bank_code: "500",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "00000058398257466"
|
||||
...> }
|
||||
...> |> IbanEx.Country.SE.to_string()
|
||||
"SE 45 500 00000058398257466"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 24
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9]{17})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
45
lib/iban_ex/country/si.ex
Normal file
45
lib/iban_ex/country/si.ex
Normal file
@@ -0,0 +1,45 @@
|
||||
defmodule IbanEx.Country.SI do
|
||||
@moduledoc """
|
||||
Slovenia IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "SI",
|
||||
...> check_digits: "56",
|
||||
...> bank_code: "26",
|
||||
...> branch_code: "330",
|
||||
...> national_check: "86",
|
||||
...> account_number: "00120390"
|
||||
...> }
|
||||
...> |> IbanEx.Country.SI.to_string()
|
||||
"SI 56 26 330 00120390 86"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 19
|
||||
@rule ~r/^(?<bank_code>[0-9]{2})(?<branch_code>[0-9]{3})(?<account_number>[0-9]{8})(?<national_check>[0-9]{2})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, account_number, national_check]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
|
||||
end
|
||||
25
lib/iban_ex/country/sk.ex
Normal file
25
lib/iban_ex/country/sk.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.SK do
|
||||
@moduledoc """
|
||||
Slovakia IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "SK",
|
||||
...> check_digits: "31",
|
||||
...> bank_code: "1200",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "0000198742637541"
|
||||
...> }
|
||||
...> |> IbanEx.Country.SK.to_string()
|
||||
"SK 31 1200 0000198742637541"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 24
|
||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{16})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
43
lib/iban_ex/country/sm.ex
Normal file
43
lib/iban_ex/country/sm.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.SM do
|
||||
@moduledoc """
|
||||
San Marino IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "SM",
|
||||
...> check_digits: "86",
|
||||
...> bank_code: "03225",
|
||||
...> branch_code: "09800",
|
||||
...> national_check: "U",
|
||||
...> account_number: "000000270100"
|
||||
...> }
|
||||
...> |> IbanEx.Country.SM.to_string()
|
||||
"SM 86 U 03225 09800 000000270100"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 27
|
||||
@rule ~r/^(?<national_check>[A-Z]{1})(?<bank_code>[0-9]{5})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{12})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, national_check, bank_code, branch_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
25
lib/iban_ex/country/sv.ex
Normal file
25
lib/iban_ex/country/sv.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.SV do
|
||||
@moduledoc """
|
||||
El Salvador IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "SV",
|
||||
...> check_digits: "62",
|
||||
...> bank_code: "CENR",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "00000000000000700025"
|
||||
...> }
|
||||
...> |> IbanEx.Country.SV.to_string()
|
||||
"SV 62 CENR 00000000000000700025"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 28
|
||||
@rule ~r/^(?<bank_code>[A-Z0-9]{4})(?<account_number>[0-9]{20})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
@@ -1,4 +1,6 @@
|
||||
defmodule IbanEx.Country.Template do
|
||||
@moduledoc false
|
||||
|
||||
alias IbanEx.Iban
|
||||
@type size() :: non_neg_integer()
|
||||
@type rule() :: Regex.t()
|
||||
@@ -7,6 +9,64 @@ defmodule IbanEx.Country.Template do
|
||||
|
||||
@callback size() :: size()
|
||||
@callback rule() :: rule()
|
||||
@callback to_s(Iban.t(), joiner()) :: String.t()
|
||||
@callback to_s(Iban.t()) :: String.t()
|
||||
@callback incomplete_rule() :: rule()
|
||||
@callback to_string(Iban.t(), joiner()) :: String.t()
|
||||
@callback to_string(Iban.t()) :: String.t()
|
||||
|
||||
defmacro __using__(_opts) do
|
||||
quote do
|
||||
alias IbanEx.Iban
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec size() :: integer()
|
||||
def size(), do: @size
|
||||
|
||||
@doc """
|
||||
Return Regex for parsing complete BBAN (part of IBAN string)
|
||||
"""
|
||||
@impl IbanEx.Country.Template
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@doc """
|
||||
Return Regex without trailing “$” for parsing incomplete BBAN (part of IBAN string) (for partial suggestions)
|
||||
"""
|
||||
@impl IbanEx.Country.Template
|
||||
@spec incomplete_rule() :: Regex.t()
|
||||
def incomplete_rule() do
|
||||
source =
|
||||
@rule
|
||||
|> Regex.source()
|
||||
|> String.slice(0..-2//1)
|
||||
|> String.replace("{", "{0,")
|
||||
|
||||
opts =
|
||||
@rule
|
||||
|> Regex.opts()
|
||||
|
||||
Regex.compile!(source, opts)
|
||||
end
|
||||
|
||||
defoverridable to_string: 1, to_string: 2, size: 0, rule: 0, incomplete_rule: 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
43
lib/iban_ex/country/tl.ex
Normal file
43
lib/iban_ex/country/tl.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.TL do
|
||||
@moduledoc """
|
||||
Timor-Leste IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "TL",
|
||||
...> check_digits: "38",
|
||||
...> bank_code: "008",
|
||||
...> branch_code: nil,
|
||||
...> national_check: "57",
|
||||
...> account_number: "00123456789101"
|
||||
...> }
|
||||
...> |> IbanEx.Country.TL.to_string()
|
||||
"TL 38 008 00123456789101 57"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 23
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9]{14})(?<national_check>[0-9]{2})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number, national_check]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
43
lib/iban_ex/country/tr.ex
Normal file
43
lib/iban_ex/country/tr.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.TR do
|
||||
@moduledoc """
|
||||
Turkey IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "TR",
|
||||
...> check_digits: "33",
|
||||
...> bank_code: "00061",
|
||||
...> branch_code: nil,
|
||||
...> national_check: "0",
|
||||
...> account_number: "0519786457841326"
|
||||
...> }
|
||||
...> |> IbanEx.Country.TR.to_string()
|
||||
"TR 33 00061 0 0519786457841326"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 26
|
||||
@rule ~r/^(?<bank_code>[A-Z0-9]{5})(?<national_check>[0-9]{1})(?<account_number>[0-9]{16})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, national_check, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
@@ -1,36 +1,24 @@
|
||||
defmodule IbanEx.Country.UA do
|
||||
@moduledoc """
|
||||
Ukrainian IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "UA",
|
||||
...> check_digits: "21",
|
||||
...> bank_code: "322313",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "0000026007233566001"
|
||||
...> }
|
||||
...> |> IbanEx.Country.UA.to_string()
|
||||
"UA 21 322313 0000026007233566001"
|
||||
```
|
||||
"""
|
||||
|
||||
alias IbanEx.Iban
|
||||
|
||||
@behaviour IbanEx.Country.Template
|
||||
|
||||
@size 29
|
||||
|
||||
@rule ~r/^(?<bank_code>[0-9]{6})(?<account_number>[0-9A-Z]{19})$/i
|
||||
|
||||
@spec size() :: 29
|
||||
def size(), do: @size
|
||||
|
||||
@spec rule() :: Regex.t()
|
||||
def rule(), do: @rule
|
||||
|
||||
@spec to_s(Iban.t()) :: binary()
|
||||
@spec to_s(Iban.t(), binary()) :: binary()
|
||||
def to_s(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: _branch_code,
|
||||
national_check: _national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, account_number]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
|
||||
25
lib/iban_ex/country/va.ex
Normal file
25
lib/iban_ex/country/va.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.VA do
|
||||
@moduledoc """
|
||||
Vatican IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "VA",
|
||||
...> check_digits: "59",
|
||||
...> bank_code: "001",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "123000012345678"
|
||||
...> }
|
||||
...> |> IbanEx.Country.VA.to_string()
|
||||
"VA 59 001 123000012345678"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 22
|
||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9]{15})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
25
lib/iban_ex/country/vg.ex
Normal file
25
lib/iban_ex/country/vg.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule IbanEx.Country.VG do
|
||||
@moduledoc """
|
||||
British Virgin Islands IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "VG",
|
||||
...> check_digits: "96",
|
||||
...> bank_code: "VPVG",
|
||||
...> branch_code: nil,
|
||||
...> national_check: nil,
|
||||
...> account_number: "0000012345678901"
|
||||
...> }
|
||||
...> |> IbanEx.Country.VG.to_string()
|
||||
"VG 96 VPVG 0000012345678901"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 24
|
||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9]{16})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
end
|
||||
43
lib/iban_ex/country/xk.ex
Normal file
43
lib/iban_ex/country/xk.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule IbanEx.Country.XK do
|
||||
@moduledoc """
|
||||
Kosovo IBAN parsing rules
|
||||
|
||||
## Examples
|
||||
|
||||
```elixir
|
||||
iex> %IbanEx.Iban{
|
||||
...> country_code: "XK",
|
||||
...> check_digits: "05",
|
||||
...> bank_code: "12",
|
||||
...> branch_code: "12",
|
||||
...> national_check: "06",
|
||||
...> account_number: "0123456789"
|
||||
...> }
|
||||
...> |> IbanEx.Country.XK.to_string()
|
||||
"XK 05 12 12 0123456789 06"
|
||||
```
|
||||
"""
|
||||
|
||||
@size 20
|
||||
@rule ~r/^(?<bank_code>[0-9]{2})(?<branch_code>[0-9]{2})(?<account_number>[0-9]{10})(?<national_check>[0-9]{2})$/i
|
||||
|
||||
use IbanEx.Country.Template
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec to_string(Iban.t()) :: binary()
|
||||
@spec to_string(Iban.t(), binary()) :: binary()
|
||||
def to_string(
|
||||
%Iban{
|
||||
country_code: country_code,
|
||||
check_digits: check_digits,
|
||||
bank_code: bank_code,
|
||||
branch_code: branch_code,
|
||||
national_check: national_check,
|
||||
account_number: account_number
|
||||
} = _iban,
|
||||
joiner \\ " "
|
||||
) do
|
||||
[country_code, check_digits, bank_code, branch_code, account_number, national_check]
|
||||
|> Enum.join(joiner)
|
||||
end
|
||||
end
|
||||
@@ -1,14 +1,27 @@
|
||||
defprotocol IbanEx.Deserialize do
|
||||
@type iban_or_error() :: IbanEx.Iban.t() | {:error, :can_not_parse_map | atom()}
|
||||
@type iban() :: IbanEx.Iban.t()
|
||||
@type iban_or_error() ::
|
||||
iban()
|
||||
| {:invalid_checksum, binary()}
|
||||
| {:invalid_format, binary()}
|
||||
| {:invalid_length, binary()}
|
||||
| {:can_not_parse_map, binary()}
|
||||
| {:unsupported_country_code, binary()}
|
||||
|
||||
@spec to_iban(t()) :: iban_or_error()
|
||||
def to_iban(value)
|
||||
end
|
||||
|
||||
defimpl IbanEx.Deserialize, for: [BitString, String] do
|
||||
alias IbanEx.{Parser, Error}
|
||||
@type iban_or_error() :: IbanEx.Iban.t() | {:error, atom()}
|
||||
@spec to_iban(String.t()) :: iban_or_error()
|
||||
@spec to_iban(binary()) :: IbanEx.Iban.t()
|
||||
@type iban() :: IbanEx.Iban.t()
|
||||
@type iban_or_error() ::
|
||||
iban()
|
||||
| {:invalid_checksum, binary()}
|
||||
| {:invalid_format, binary()}
|
||||
| {:invalid_length, binary()}
|
||||
| {:can_not_parse_map, binary()}
|
||||
| {:unsupported_country_code, binary()}
|
||||
def to_iban(string) do
|
||||
case Parser.parse(string) do
|
||||
{:ok, iban} -> iban
|
||||
@@ -18,10 +31,17 @@ def to_iban(string) do
|
||||
end
|
||||
|
||||
defimpl IbanEx.Deserialize, for: Map do
|
||||
alias IbanEx.Iban
|
||||
@type iban_or_error() :: IbanEx.Iban.t() | {:error, :can_not_parse_map}
|
||||
alias IbanEx.{Iban, Error}
|
||||
|
||||
@type iban() :: IbanEx.Iban.t()
|
||||
@type iban_or_error() ::
|
||||
iban()
|
||||
| {:invalid_checksum, binary()}
|
||||
| {:invalid_format, binary()}
|
||||
| {:invalid_length, binary()}
|
||||
| {:can_not_parse_map, binary()}
|
||||
| {:unsupported_country_code, binary()}
|
||||
|
||||
@spec to_iban(map()) :: iban_or_error()
|
||||
def to_iban(
|
||||
%{
|
||||
country_code: _country_code,
|
||||
@@ -49,13 +69,10 @@ def to_iban(
|
||||
to_iban(atomized_map)
|
||||
end
|
||||
|
||||
def to_iban(map) when is_map(map), do: {:error, :can_not_parse_map}
|
||||
def to_iban(map) when is_map(map), do: {:can_not_parse_map, Error.message(:can_not_parse_map)}
|
||||
end
|
||||
|
||||
defimpl IbanEx.Deserialize, for: List do
|
||||
alias IbanEx.Iban
|
||||
@type iban_or_error() :: IbanEx.Iban.t() | {:error, :can_not_parse_map}
|
||||
|
||||
@spec to_iban(list()) :: iban_or_error()
|
||||
def to_iban(list), do: struct(Iban, Map.new(list))
|
||||
end
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
defmodule IbanEx.Error do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
@moduledoc false
|
||||
|
||||
@type error() ::
|
||||
:unsupported_country_code
|
||||
@@ -9,6 +7,8 @@ defmodule IbanEx.Error do
|
||||
| :invalid_length
|
||||
| :invalid_checksum
|
||||
| :can_not_parse_map
|
||||
| :length_to_long
|
||||
| :length_to_short
|
||||
| atom()
|
||||
@type errors() :: [error()]
|
||||
@errors [
|
||||
@@ -16,7 +16,9 @@ defmodule IbanEx.Error do
|
||||
:invalid_format,
|
||||
:invalid_length,
|
||||
:invalid_checksum,
|
||||
:can_not_parse_map
|
||||
:can_not_parse_map,
|
||||
:length_to_long,
|
||||
:length_to_short
|
||||
]
|
||||
|
||||
@messages [
|
||||
@@ -24,7 +26,9 @@ defmodule IbanEx.Error do
|
||||
invalid_format: "IBAN violates required format",
|
||||
invalid_length: "IBAN violates the required length",
|
||||
invalid_checksum: "IBAN's checksum is invalid",
|
||||
can_not_parse_map: "Can't parse map to IBAN struct"
|
||||
can_not_parse_map: "Can't parse map to IBAN struct",
|
||||
length_to_long: "IBAN longer then required length",
|
||||
length_to_short: "IBAN shorter then required length"
|
||||
]
|
||||
|
||||
@spec message(error()) :: String.t()
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
defmodule IbanEx.Formatter do
|
||||
@moduledoc false
|
||||
|
||||
alias IbanEx.Country
|
||||
import IbanEx.Commons, only: [normalize: 1]
|
||||
|
||||
@@ -28,7 +30,7 @@ def format(iban, :compact),
|
||||
|
||||
def format(iban, :pretty) do
|
||||
country_module = Country.country_module(iban.country_code)
|
||||
country_module.to_s(iban)
|
||||
country_module.to_string(iban)
|
||||
end
|
||||
|
||||
def format(iban, :splitted) do
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
defmodule IbanEx.Iban do
|
||||
@moduledoc false
|
||||
|
||||
alias IbanEx.Formatter
|
||||
alias IbanEx.{Serialize}
|
||||
|
||||
|
||||
@@ -1,28 +1,69 @@
|
||||
defmodule IbanEx.Parser do
|
||||
@moduledoc false
|
||||
|
||||
alias IbanEx.{Country, Iban, Validator}
|
||||
import IbanEx.Commons, only: [normalize_and_slice: 2]
|
||||
|
||||
@type iban_string() :: String.t()
|
||||
@type country_code_string() :: <<_::16>>
|
||||
@type check_digits_string() :: <<_::16>>
|
||||
@type iban_or_error() :: IbanEx.Iban.t() | {:error, atom()}
|
||||
|
||||
@spec parse({:ok, String.t()} | String.t()) :: iban_or_error()
|
||||
@type iban() :: IbanEx.Iban.t()
|
||||
@type iban_or_error() ::
|
||||
{:ok, iban()}
|
||||
| {:invalid_checksum, binary()}
|
||||
| {:invalid_format, binary()}
|
||||
| {:invalid_length, binary()}
|
||||
| {:can_not_parse_map, binary()}
|
||||
| {:unsupported_country_code, binary()}
|
||||
|
||||
@spec parse({:ok, binary()}) :: iban_or_error()
|
||||
def parse({:ok, iban_string}), do: parse(iban_string)
|
||||
|
||||
@spec parse(binary()) :: iban_or_error()
|
||||
def parse(iban_string) do
|
||||
with {:ok, valid_iban} <- Validator.validate(iban_string) do
|
||||
case Validator.validate(iban_string) do
|
||||
{:ok, valid_iban} ->
|
||||
iban_map = %{
|
||||
country_code: country_code(valid_iban),
|
||||
check_digits: check_digits(valid_iban),
|
||||
check_digits: check_digits(valid_iban)
|
||||
}
|
||||
|
||||
regex = Country.country_module(iban_map.country_code).rule()
|
||||
bban = bban(iban_string)
|
||||
bban_map = for {key, val} <- Regex.named_captures(regex, bban), into: %{}, do: {String.to_atom(key), val}
|
||||
bban_map =
|
||||
iban_string
|
||||
|> bban()
|
||||
|> parse_bban(iban_map.country_code)
|
||||
|
||||
{:ok, struct(Iban, Map.merge(iban_map, bban_map))}
|
||||
else
|
||||
{:error, error_type} -> {:error, error_type}
|
||||
|
||||
{:error, error_type} ->
|
||||
{:error, error_type}
|
||||
end
|
||||
end
|
||||
|
||||
@spec parse_bban(binary(), <<_::16>>) :: map()
|
||||
def parse_bban(bban_string, country_code, options \\ [incomplete: false])
|
||||
|
||||
def parse_bban(bban_string, country_code, incomplete: true) do
|
||||
Country.country_module(country_code).incomplete_rule()
|
||||
|> parse_bban_by_regex(bban_string)
|
||||
end
|
||||
|
||||
def parse_bban(bban_string, country_code, _options) do
|
||||
Country.country_module(country_code).rule()
|
||||
|> parse_bban_by_regex(bban_string)
|
||||
end
|
||||
|
||||
defp parse_bban_by_regex(_regex, nil), do: %{}
|
||||
defp parse_bban_by_regex(regex, bban_string) do
|
||||
case Regex.named_captures(regex, bban_string) do
|
||||
map when is_map(map) ->
|
||||
for {key, val} <- map,
|
||||
into: %{},
|
||||
do: {String.to_atom(key), val}
|
||||
|
||||
nil ->
|
||||
%{}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
defmodule IbanEx.Serialize do
|
||||
@moduledoc false
|
||||
|
||||
alias IbanEx.{Iban, Formatter}
|
||||
|
||||
@spec to_string(Iban.t()) :: String.t()
|
||||
def to_string(iban), do: Formatter.format(iban)
|
||||
|
||||
@spec to_map(Iban.t()) :: Map.t()
|
||||
@spec to_map(Iban.t()) :: map()
|
||||
def to_map(iban), do: Map.from_struct(iban)
|
||||
end
|
||||
|
||||
@@ -1,28 +1,61 @@
|
||||
defmodule IbanEx.Validator do
|
||||
@moduledoc false
|
||||
|
||||
alias IbanEx.{Country, Parser}
|
||||
alias IbanEx.Validator.Replacements
|
||||
import IbanEx.Commons, only: [normalize: 1]
|
||||
|
||||
@spec validate(String.t()) :: {:ok, String.t()} | {:error}
|
||||
defp error_accumulator(acc, error_message)
|
||||
defp error_accumulator(acc, {:error, error}), do: [error | acc]
|
||||
defp error_accumulator(acc, _), do: acc
|
||||
|
||||
defp violation_functions(),
|
||||
do: [
|
||||
{&__MODULE__.iban_violates_format?/1, {:error, :invalid_format}},
|
||||
{&__MODULE__.iban_unsupported_country?/1, {:error, :unsupported_country_code}},
|
||||
{&__MODULE__.iban_violates_length?/1, {:error, :invalid_length}},
|
||||
{&__MODULE__.iban_violates_country_rule?/1, {:error, :invalid_format_for_country}},
|
||||
{&__MODULE__.iban_violates_checksum?/1, {:error, :invalid_checksum}}
|
||||
]
|
||||
|
||||
@doc """
|
||||
Accumulate check results in the list of errors
|
||||
Check iban_violates_format?, iban_unsupported_country?, iban_violates_length?, iban_violates_country_rule?, iban_violates_checksum?
|
||||
"""
|
||||
@spec violations(String.t()) :: [] | [atom()]
|
||||
def violations(iban) do
|
||||
violation_functions()
|
||||
|> Enum.reduce([], fn {fun, value}, acc -> error_accumulator(acc, !fun.(iban) or value) end)
|
||||
|> Enum.reverse()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Make checks in this order step-by-step before first error ->
|
||||
|
||||
iban_violates_format?,
|
||||
iban_unsupported_country?,
|
||||
iban_violates_length?,
|
||||
iban_violates_country_rule?,
|
||||
iban_violates_checksum?
|
||||
|
||||
"""
|
||||
@type iban() :: binary()
|
||||
@type iban_or_error() ::
|
||||
{:ok, iban()}
|
||||
| {:invalid_checksum, binary()}
|
||||
| {:invalid_format, binary()}
|
||||
| {:invalid_length, binary()}
|
||||
| {:unsupported_country_code, binary()}
|
||||
@spec validate(String.t()) :: {:ok, String.t()} | {:error, atom()}
|
||||
|
||||
def validate(iban) do
|
||||
cond do
|
||||
iban_violates_format?(iban) ->
|
||||
{:error, :invalid_format}
|
||||
|
||||
iban_unsupported_country?(iban) ->
|
||||
{:error, :unsupported_country_code}
|
||||
|
||||
iban_violates_length?(iban) ->
|
||||
{:error, :invalid_length}
|
||||
|
||||
iban_violates_country_rule?(iban) ->
|
||||
{:error, :invalid_format}
|
||||
|
||||
iban_violates_checksum?(iban) ->
|
||||
{:error, :invalid_checksum}
|
||||
|
||||
true ->
|
||||
{:ok, normalize(iban)}
|
||||
iban_violates_format?(iban) -> {:error, :invalid_format}
|
||||
iban_unsupported_country?(iban) -> {:error, :unsupported_country_code}
|
||||
iban_violates_length?(iban) -> {:error, :invalid_length}
|
||||
iban_violates_country_rule?(iban) -> {:error, :invalid_format_for_country}
|
||||
iban_violates_checksum?(iban) -> {:error, :invalid_checksum}
|
||||
true -> {:ok, normalize(iban)}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,12 +68,12 @@ defp size(iban) do
|
||||
|
||||
# - Check whether a given IBAN violates the required format.
|
||||
@spec iban_violates_format?(String.t()) :: boolean
|
||||
defp iban_violates_format?(iban),
|
||||
def iban_violates_format?(iban),
|
||||
do: Regex.match?(~r/[^A-Z0-9]/i, normalize(iban))
|
||||
|
||||
# - Check whether a given IBAN violates the supported countries.
|
||||
@spec iban_unsupported_country?(String.t()) :: boolean
|
||||
defp iban_unsupported_country?(iban) do
|
||||
def iban_unsupported_country?(iban) do
|
||||
supported? =
|
||||
iban
|
||||
|> Parser.country_code()
|
||||
@@ -49,33 +82,54 @@ defp iban_unsupported_country?(iban) do
|
||||
!supported?
|
||||
end
|
||||
|
||||
# - Check whether a given IBAN violates the required length.
|
||||
@doc "Check whether a given IBAN violates the required length."
|
||||
@spec iban_violates_length?(String.t()) :: boolean
|
||||
defp iban_violates_length?(iban) do
|
||||
def iban_violates_length?(iban) do
|
||||
with country_code <- Parser.country_code(iban),
|
||||
country_module <- Country.country_module(country_code) do
|
||||
country_module when is_atom(country_module) <- Country.country_module(country_code) do
|
||||
size(iban) != country_module.size()
|
||||
else
|
||||
{:error, _} -> true
|
||||
{:error, _error} -> true
|
||||
end
|
||||
end
|
||||
|
||||
# - Check whether a given IBAN violates the country rules.
|
||||
@doc "Check length of IBAN"
|
||||
@spec check_iban_length(String.t()) :: {:error, :length_to_short | :length_to_long} | :ok
|
||||
def check_iban_length(iban) do
|
||||
case iban_unsupported_country?(iban) do
|
||||
true ->
|
||||
{:error, :unsupported_country_code}
|
||||
|
||||
false ->
|
||||
country_module =
|
||||
iban
|
||||
|> Parser.country_code()
|
||||
|> Country.country_module()
|
||||
|
||||
case country_module.size() - size(iban) do
|
||||
diff when diff > 0 -> {:error, :length_to_short}
|
||||
diff when diff < 0 -> {:error, :length_to_long}
|
||||
0 -> :ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@doc "Check whether a given IBAN violates the country rules"
|
||||
@spec iban_violates_country_rule?(String.t()) :: boolean
|
||||
defp iban_violates_country_rule?(iban) do
|
||||
def iban_violates_country_rule?(iban) do
|
||||
with country_code <- Parser.country_code(iban),
|
||||
bban <- Parser.bban(iban),
|
||||
country_module <- Country.country_module(country_code),
|
||||
country_module when is_atom(country_module) <- Country.country_module(country_code),
|
||||
rule <- country_module.rule() do
|
||||
!Regex.match?(rule, bban)
|
||||
else
|
||||
{:error, _} -> true
|
||||
_ -> true
|
||||
end
|
||||
end
|
||||
|
||||
# - Check whether a given IBAN violates the required checksum.
|
||||
@doc "Check whether a given IBAN violates the required checksum."
|
||||
@spec iban_violates_checksum?(String.t()) :: boolean
|
||||
defp iban_violates_checksum?(iban) do
|
||||
def iban_violates_checksum?(iban) do
|
||||
check_sum_base = Parser.bban(iban) <> Parser.country_code(iban) <> "00"
|
||||
|
||||
replacements = Replacements.replacements()
|
||||
|
||||
3
mix.exs
3
mix.exs
@@ -2,7 +2,7 @@ defmodule IbanEx.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
@source_url "https://g.tulz.dev/opensource/iban-ex"
|
||||
@version "0.1.0"
|
||||
@version "0.1.6"
|
||||
|
||||
def project do
|
||||
[
|
||||
@@ -68,7 +68,6 @@ defp deps do
|
||||
{:ex_doc, ">= 0.0.0", only: ~w(dev test)a, runtime: false},
|
||||
{:sobelow, ">= 0.0.0", only: ~w(dev test)a, runtime: false},
|
||||
{:mix_audit, ">= 0.0.0", only: ~w(dev test)a, runtime: false},
|
||||
{:esbuild, "~> 0.7.0", runtime: Mix.env() == :dev},
|
||||
{:observer_cli, "~> 1.7.4", only: :dev, runtime: false},
|
||||
{:elixir_sense, github: "elixir-lsp/elixir_sense", only: ~w(dev)a}
|
||||
|
||||
|
||||
@@ -1,8 +1,162 @@
|
||||
defmodule IbanExTest do
|
||||
use ExUnit.Case
|
||||
doctest IbanEx
|
||||
alias IbanEx.{Country, Iban, Parser}
|
||||
use ExUnit.Case, async: true
|
||||
doctest_file "README.md"
|
||||
doctest IbanEx.Country.AD
|
||||
doctest IbanEx.Country.AE
|
||||
doctest IbanEx.Country.AL
|
||||
doctest IbanEx.Country.AT
|
||||
doctest IbanEx.Country.AZ
|
||||
doctest IbanEx.Country.BA
|
||||
doctest IbanEx.Country.BE
|
||||
doctest IbanEx.Country.BG
|
||||
doctest IbanEx.Country.BH
|
||||
doctest IbanEx.Country.BR
|
||||
doctest IbanEx.Country.CH
|
||||
doctest IbanEx.Country.CR
|
||||
doctest IbanEx.Country.CY
|
||||
doctest IbanEx.Country.CZ
|
||||
doctest IbanEx.Country.DE
|
||||
doctest IbanEx.Country.DK
|
||||
doctest IbanEx.Country.DO
|
||||
doctest IbanEx.Country.EE
|
||||
doctest IbanEx.Country.EG
|
||||
doctest IbanEx.Country.ES
|
||||
doctest IbanEx.Country.FI
|
||||
doctest IbanEx.Country.FO
|
||||
doctest IbanEx.Country.FR
|
||||
doctest IbanEx.Country.GB
|
||||
doctest IbanEx.Country.GE
|
||||
doctest IbanEx.Country.GI
|
||||
doctest IbanEx.Country.GL
|
||||
doctest IbanEx.Country.GR
|
||||
doctest IbanEx.Country.GT
|
||||
doctest IbanEx.Country.JO
|
||||
doctest IbanEx.Country.HR
|
||||
doctest IbanEx.Country.HU
|
||||
doctest IbanEx.Country.IE
|
||||
doctest IbanEx.Country.IL
|
||||
doctest IbanEx.Country.IT
|
||||
doctest IbanEx.Country.KZ
|
||||
doctest IbanEx.Country.KW
|
||||
doctest IbanEx.Country.LB
|
||||
doctest IbanEx.Country.LI
|
||||
doctest IbanEx.Country.LT
|
||||
doctest IbanEx.Country.LU
|
||||
doctest IbanEx.Country.LV
|
||||
doctest IbanEx.Country.MC
|
||||
doctest IbanEx.Country.MD
|
||||
doctest IbanEx.Country.ME
|
||||
doctest IbanEx.Country.MK
|
||||
doctest IbanEx.Country.MR
|
||||
doctest IbanEx.Country.MT
|
||||
doctest IbanEx.Country.NL
|
||||
doctest IbanEx.Country.NO
|
||||
doctest IbanEx.Country.PK
|
||||
doctest IbanEx.Country.PL
|
||||
doctest IbanEx.Country.PT
|
||||
doctest IbanEx.Country.QA
|
||||
doctest IbanEx.Country.RO
|
||||
doctest IbanEx.Country.RS
|
||||
doctest IbanEx.Country.SA
|
||||
doctest IbanEx.Country.SE
|
||||
doctest IbanEx.Country.SI
|
||||
doctest IbanEx.Country.SK
|
||||
doctest IbanEx.Country.SM
|
||||
doctest IbanEx.Country.SV
|
||||
doctest IbanEx.Country.TL
|
||||
doctest IbanEx.Country.TR
|
||||
doctest IbanEx.Country.UA
|
||||
doctest IbanEx.Country.VA
|
||||
doctest IbanEx.Country.VG
|
||||
doctest IbanEx.Country.XK
|
||||
|
||||
test "greets the world" do
|
||||
assert IbanEx.hello() == :world
|
||||
@ibans [
|
||||
"AL47212110090000000235698741",
|
||||
"AD1200012030200359100100",
|
||||
"AT611904300234573201",
|
||||
"AZ21NABZ00000000137010001944",
|
||||
"BH67BMAG00001299123456",
|
||||
"BE68539007547034",
|
||||
"BA391290079401028494",
|
||||
"BR1800360305000010009795493C1",
|
||||
"BG80BNBG96611020345678",
|
||||
"CR05015202001026284066",
|
||||
"HR1210010051863000160",
|
||||
"CY17002001280000001200527600",
|
||||
"CZ6508000000192000145399",
|
||||
"DK5000400440116243",
|
||||
"DO28BAGR00000001212453611324",
|
||||
"EG380019000500000000263180002",
|
||||
"SV62CENR00000000000000700025",
|
||||
"EE382200221020145685",
|
||||
"FO6264600001631634",
|
||||
"FI2112345600000785",
|
||||
"FR1420041010050500013M02606",
|
||||
"GE29NB0000000101904917",
|
||||
"DE89370400440532013000",
|
||||
"GI75NWBK000000007099453",
|
||||
"GR1601101250000000012300695",
|
||||
"GL8964710001000206",
|
||||
"GT82TRAJ01020000001210029690",
|
||||
"HU42117730161111101800000000",
|
||||
"IS140159260076545510730339",
|
||||
"IE29AIBK93115212345678",
|
||||
"IL620108000000099999999",
|
||||
"IT60X0542811101000000123456",
|
||||
"JO94CBJO0010000000000131000302",
|
||||
"KZ86125KZT5004100100",
|
||||
"XK051212012345678906",
|
||||
"KW81CBKU0000000000001234560101",
|
||||
"LV80BANK0000435195001",
|
||||
"LB62099900000001001901229114",
|
||||
"LI21088100002324013AA",
|
||||
"LT121000011101001000",
|
||||
"LU280019400644750000",
|
||||
"MK07250120000058984",
|
||||
"MT84MALT011000012345MTLCAST001S",
|
||||
"MR1300020001010000123456753",
|
||||
"MC5811222000010123456789030",
|
||||
"ME25505000012345678951",
|
||||
"NL91ABNA0417164300",
|
||||
"NO9386011117947",
|
||||
"PK36SCBL0000001123456702",
|
||||
"PL61109010140000071219812874",
|
||||
"PT50000201231234567890154",
|
||||
"QA58DOHB00001234567890ABCDEFG",
|
||||
"MD24AG000225100013104168",
|
||||
"RO49AAAA1B31007593840000",
|
||||
"SM86U0322509800000000270100",
|
||||
"SA0380000000608010167519",
|
||||
"RS35260005601001611379",
|
||||
"SK3112000000198742637541",
|
||||
"SI56263300012039086",
|
||||
"ES9121000418450200051332",
|
||||
"SE4550000000058398257466",
|
||||
"CH9300762011623852957",
|
||||
"TL380080012345678910157",
|
||||
"TR330006100519786457841326",
|
||||
"UA213223130000026007233566001",
|
||||
"AE070331234567890123456",
|
||||
"GB29NWBK60161331926819",
|
||||
"VA59001123000012345678",
|
||||
"VG96VPVG0000012345678901"
|
||||
]
|
||||
|
||||
test "parsing valid IBANs from available countries returns {:ok, %IbanEx.Iban{}}" do
|
||||
assert Enum.all?(@ibans, fn iban ->
|
||||
iban_country = iban |> String.upcase() |> String.slice(0..1)
|
||||
|
||||
case {Country.is_country_code_supported?(iban_country), Parser.parse(iban)} do
|
||||
{true, {:ok, %Iban{}}} ->
|
||||
true
|
||||
|
||||
{false, {:error, :unsupported_country_code}} ->
|
||||
true
|
||||
|
||||
_ ->
|
||||
false
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
18
test/iban_ex_validator_test.exs
Normal file
18
test/iban_ex_validator_test.exs
Normal file
@@ -0,0 +1,18 @@
|
||||
defmodule IbanExValidatorTest do
|
||||
alias IbanEx.{Validator}
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
test "check IBANs length" do
|
||||
cases = [
|
||||
{"FG2112345CC6000007", {:error, :unsupported_country_code}},
|
||||
{"UK2112345CC6000007", {:error, :unsupported_country_code}},
|
||||
{"FI2112345CC6000007", :ok},
|
||||
{"FI2112345CC6000007a", {:error, :length_to_long}},
|
||||
{"FI2112345CC600007", {:error, :length_to_short}}
|
||||
]
|
||||
|
||||
Enum.all?(cases, fn {iban, result} ->
|
||||
assert Validator.check_iban_length(iban) == result
|
||||
end)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user