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

Satchel picture Satchel · May 6, 2011 · Viewed 7.1k times · Source

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 it really doesn't work for us phone number, it's designed for international numbers.

Is there an equivalent?

Thanks.

http://rubygems.org/gems/phony

Answer

Jason McLaren picture Jason McLaren · Dec 8, 2011

Earlier this year, I reviewed a bunch of ruby gems that parse and format phone numbers. They fall into a number of groups (see below). TLDR: I used 'phone'. It might work for you because you can specify a default country code that it uses if your phone number doesn't include one.

1) US-centric:

big-phoney (0.1.4)
phone_wrangler (0.1.3)
simple_phone_number (0.1.9)

2) depends on rails or active_record:

phone_number (1.2.0)
validates_and_formats_phones (0.0.7)

3) forks of 'phone' that have been merged back into the trunk:

elskwid-phone (0.9.9.4)
tfe-phone (0.9.9.1)

4) relies on you to know the region ahead of time

phoney (0.1.0)

5) Kind of almost works for me

phone (0.9.9.3)

6) does not contain the substring 'phone' in the gem name (edit: I see you tried this one)

phony (1.6.1)

These groupings may be somewhat unfair or out of date so feel free to comment. I must admit I was a little frustrated at the time at how many people had partially re-invented this particular wheel.