Skip to content

Instantly share code, notes, and snippets.

@rosiehoyem
Created October 14, 2013 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosiehoyem/6977525 to your computer and use it in GitHub Desktop.
Save rosiehoyem/6977525 to your computer and use it in GitHub Desktop.
Normalize phone numbers TODO, day 5
def normalize_phone_number(phone)
if phone[/a-zA-Z/] == nil
phone.each_char do |x|
if !(x.match(/[\d]/))
phone.delete! x
end
end
phone.insert(0, "(")
phone.insert(4, ") ")
phone.insert(9, "-")
#phone = "(#{phone[0]}#{phone[1]}#{phone[2]}) #{phone[3]}#{phone[4]}#{phone[5]}-#{phone[6]}#{phone[7]}#{phone[8]}#{phone[9]}"
else
phone
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment