Created
February 5, 2015 10:39
-
-
Save troyk/db7c3b7a7b50ba6de1aa to your computer and use it in GitHub Desktop.
This aint so bad is it??
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
meh...... it's too new dude. Hell, Ecto is < v1