Skip to content

Instantly share code, notes, and snippets.

@troyk
Created February 5, 2015 10:39
Show Gist options
  • Save troyk/db7c3b7a7b50ba6de1aa to your computer and use it in GitHub Desktop.
Save troyk/db7c3b7a7b50ba6de1aa to your computer and use it in GitHub Desktop.
This aint so bad is it??
defmodule Rocket.Stringer do
def sanitize_phone(ph) do
ph = Regex.replace(~r/[^0-9]/,ph,"")
case Regex.run(~r/\d{5,10}$/,ph) do
[phone] -> phone
_ -> nil
end
end
def format_phone(ph) do
ph = sanitize_phone(ph)
case String.length(ph) do
10 -> "(#{String.slice(ph,0,3)})#{String.slice(ph,3,3)}-#{String.slice(ph,6,4)}"
7 -> "#{String.slice(ph,0,3)}-#{String.slice(ph,3,4)}"
_ -> ph
end
end
end
@rbagley0278
Copy link

meh...... it's too new dude. Hell, Ecto is < v1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment