# `LedgerUI.Components.PhoneInput.Format`
[🔗](https://github.com/devaction-labs/ledger_ui/blob/v0.2.0/lib/ledger_ui/components/phone_input.ex#L237)

Country data and number formatting for `LedgerUI.Components.PhoneInput`.

`e164/2` reads a submitted number the way the field does and normalizes it to E.164. It
rejects what cannot be a number but does not know which numbers a carrier issues; for that,
check the E.164 string with a library that has number metadata.

    iex> LedgerUI.Components.PhoneInput.Format.e164("(11) 91234-5678", "BR")
    {:ok, "+5511912345678"}
    iex> LedgerUI.Components.PhoneInput.Format.e164("+351 912 345 678", "BR")
    {:ok, "+351912345678"}
    iex> LedgerUI.Components.PhoneInput.Format.e164("12", "BR")
    {:error, :too_short}

# `all`

All the countries known to the field.

# `e164`

```elixir
@spec e164(String.t() | nil, String.t()) :: {:ok, String.t()} | {:error, atom()}
```

Reads a submitted number and normalizes it to E.164.

A number starting with `+` (or `00`) carries its own country; any other is read as a national
number of `default_country` (its trunk prefix is dropped). Returns `{:ok, "+5511912345678"}` or
`{:error, reason}` with `:empty`, `:unknown_country`, `:too_short` or `:too_long`.

# `format_national`

Formats national `digits` in the pattern of `country` (a map from `all/0` or an ISO code).
A separator only appears when a digit follows it, and extra digits are kept.

    iex> LedgerUI.Components.PhoneInput.Format.format_national("11912345678", "BR")
    "(11) 91234-5678"
    iex> LedgerUI.Components.PhoneInput.Format.format_national("119", "BR")
    "(11) 9"

# `get`

A country by ISO 3166-1 alpha-2 code, or `nil`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
