Groups
Groups
Sign in
Groups
Groups
Ruby on Rails Taiwan
Conversations
About
Send feedback
Help
number_to_tw_phone
3 views
Skip to first unread message
CFC
unread,
Nov 14, 2008, 1:42:16 PM
11/14/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails Taiwan
def number_to_tw_phone(phone, cellphone=false)
raise "Phone number error!" if phone.size < 9 || phone.size > 10
|| (phone.size < 10 if cellphone)
no = phone.split("")
return %{#{no[0..3].join}-#{no[4..6]}-#{no[7..9]}} if cellphone
return %{(#{no[0..2].join})#{no[3..5]}-#{no[6..8].join}} if no
[0..2].join == "089" # Tai-dong
return %{(#{no[0..1].join})#{no[2..4]}-#{no[5..8].join}} if
phone.size == 9
return %{(#{no[0..1].join})#{no[2..5]}-#{no[6..9].join}} if
phone.size == 10
end
puts number_to_tw_phone("0987654321", true) #=> 0987-654-321
puts number_to_tw_phone("0234567890") #=> (02)3456-7890
puts number_to_tw_phone("087654321") #=> (08)765-4321
puts number_to_tw_phone("089876543") #=> (089)876-543 #=> 這
是台東的電話
:)
Reply all
Reply to author
Forward
0 new messages