Phone numbers are not a big deal if you can validate the input at the time you’ve got a human right there. My enterprise tends not to have that ability, as we receive large files from clients with little or no validation done. Rather than abandon #s which don’t validate, I wrote this to parse and normalize a string into a standard NANP phone number, possibly including an extension.

References: NANPA: North American Numbering Plan Administration nanpa.com/

require “dialable” pn = Dialable::NANP.parse(“+1(800)555-1212 ext 1234”)

>> puts pn.to_s // Pretty output 800-555-1212 x1234

>> puts pn.to_digits // Address book friendly 8005551212 x1234

>> puts pn.to_dialable // PBX friendly 8005551212

>> puts pn.extension 1234

-chorn