EctoPhone — another ecto type, almost but not quite like the existing ones

Just released a new library, and thought I’d share: EctoPhone. It’s heavily inspired by EctoPhoneNumber, but I wanted a few different behaviors.

It’s parameterized, and you can configure it with a default country prefix, so when 10-digit national numbers are sent in it will automatically add the country code rather than just returning an “is invalid” error. Right now it defaults to 1, but if that winds up being too opinionated and/or fragile for people, I don’t mind releasing a new version with breaking changes based on feedback.

You can also configure it at the application level or on a specific field to print in different formats.

The library also includes a ~PHONE sigil, which can help for writing more concise tests (or other code).

Hope this is helpful for others!

5 Likes