View Source EctoPhone (EctoPhone v1.0.1)

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
end

Configuration

config :ecto_phone, default_prefix: 1, default_format: :national

EctoPhone 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 to 1 if not configured by the application or by the field.
  • :default_format: The ex_phone_number format to use when printing phone numbers as strings. Defaults to :international. Valid options: :e164, :international, :national, :rfc3966

Summary

Functions

Configures a specific field.

Handles the sigil ~PHONE for an EctoPhone struct.

Types

@type t() :: %EctoPhone{e164: term(), format: term()}

Functions

Configures a specific field.

schema "table_name" do
  field :phone, EctoPhone
  field :phone, EctoPhone, default_prefix: 1
  field :phone, EctoPhone, format: :national
end
Link to this function

sigil_PHONE(number, modifiers)

View Source

Handles the sigil ~PHONE for an EctoPhone struct.

Modifers

  • e: Format as :e164
  • i: Format as :international
  • n: Format as :national