Is there a gem that normalizes and format US phone numbers in ruby?

前端 未结 6 2056
悲哀的现实
悲哀的现实 2021-01-02 00:10

I was using phony to format phone numbers (meaning, if I put in xxx-xxx-xxxx it would convert to a string, and also tell if there is a (1) before to remove it).

But

6条回答
  •  滥情空心
    2021-01-02 00:24

    def format_phone_numbers(n)
        "(#{n[-10..-8]}) #{n[-7..-5]}-#{n[-4..-1]}"
    end
    
    format_phone_numbers('555555555555')
    

    "(555) 555-5555"

提交回复
热议问题