A4J
A4J

Reputation: 889

Converting local numbers into international format (for use with Rails and services such as Nexmo/Twilo)

I want to verify my users phone numbers using a service such as Nexmo or Twilo.

To send a message via these services I need to supply the international number, however, I do not want to have to ask my users to provide the full international number - just their normal number that they would give to anyone in their own country (I don't expect them to know their international dialling codes, etc).

So what is the best way to convert a local national number into an international one? As well as their number, each user will be asked to provide their country. (My user base will be international.)

Upvotes: 2

Views: 1372

Answers (2)

bcoyle73
bcoyle73

Reputation: 33

The phony_rails gem provides international formatting and validation. This is a rails wrapper for phony giving you view helpers and model validators. To see all the countries it supports see the phony repository.

Upvotes: 0

beanserver
beanserver

Reputation: 652

Google’s opensource libphonenumber project is probably the best tool for any sort of work involving phone numbers. Given a country and phone number, libphonenumber can be used to produce the E.164 format which Twilio prefers. It can also produce example phone numbers to improve the accuracy of the data you collect in the first place. A ruby port is available. An example Twilio app using libphonenumber in php can be found in Twilio Skills training.

Upvotes: 3

Related Questions