Ruby library for parsing, validating and formatting phone numbers

Tomislav Car has just released Phone, Ruby library for phone number parsing, validation and formatting. It should save you a lot of time if you need any of the following:

* you have area where users input phone numbers in many different formats
* output phone numbers in specific format
* you need to send SMS messages from your app
* …

You can initialize new Phone object with Phone.new

  Phone.new('5125486', '91', '385')

or

  Phone.new(:number => '5125486', :area_code => '91', :country_code => '385')

Parsing is done using Phone.parse method

    Phone.parse '091/512-5486', :country_code => '385'
    Phone.parse '(091) 512 5486', :country_code => '385'

It is smart to set default contry code first so you don’t have to provide it as option every time

    Phone.default_country_code = '385'
    Phone.parse '091/512-5486'
    Phone.parse '(091) 512 5486'

Fow now, Phone works only for Croatian, Slovenian, Bosnian and Serbian phone numbers, but Tomislav is collecting data to support other countries.

Go check it out

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>