View Source EctoPhone (EctoPhone v1.0.2)
A custom Ecto type for phone numbers, with configuration for default country prefix and formatting style.
Usage
The EctoPhone type may be used in place of :string fields.
defmodule MySchema do
use Ecto.Schema
schema "table_name" do
field :phone, EctoPhone
field :phone, EctoPhone, default_prefix: 1
field :phone, EctoPhone, format: :national
end
endConfiguration
config :ecto_phone, default_prefix: 1, default_format: :nationalEctoPhone may be configured at the application level with the following
options.
:default_prefix: A country prefix to use when none is provided by users. Set to1if not configured by the application or by the field.:default_format: Theex_phone_numberformat to use when printing phone numbers as strings. Defaults to:international. Valid options::e164,:international,:national,:rfc3966
Summary
Types
e—:e164i—:internationaln—:nationalrfc—:rfc3966
Functions
Configures a specific field with init_opts/0.
Handles the sigil ~PHONE for an EctoPhone struct.
Types
@type format() :: :e164 | :international | :national | :rfc3966
@type format_modifier() :: charlist()
e—:e164i—:internationaln—:nationalrfc—:rfc3966
Functions
Configures a specific field with init_opts/0.
schema "table_name" do
field :phone, EctoPhone
field :phone, EctoPhone, default_prefix: 1
field :phone, EctoPhone, format: :national
end
@spec sigil_PHONE(binary(), format_modifier()) :: t()
Handles the sigil ~PHONE for an EctoPhone struct.
Modifers
e— format as:e164i— format as:internationaln— format as:nationalrfc— format as:rfc3966