Created
October 14, 2013 15:30
-
-
Save rosiehoyem/6977525 to your computer and use it in GitHub Desktop.
Normalize phone numbers TODO, day 5
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
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