You are here

How to Validate Phone Numbers Using the Twilio Lookup API

Twilio is a San Francisco-based cloud communications provider whose services handle text messaging for companies such as Uber and AWS, among many, many others. The service connects Web browsers and backend servers to make requests to the Twilio REST API to dispatch to the person being contacted, delivering a predefined message, such as the status of an AWS service, from the specified URL.

The company also offers a Lookup API that retrieves detailed insights into every phone number, so users can get information on who is calling them, protect themselves against spam and fraud, or enhance outgoing message efficiency by identifying dormant numbers to reduce undelivered messages. In this tutorial on the Twilio Blog, Sam Agnew describes how to use the Lookup API to validate phone numbers in Node/JavaScript.

Followers need to have Node.js and npm installed, with a free Twilio account and your account SID and Auth Token handy. Twilio’s Lookup page offers an easy way to play around with the API to see what it returns, and the author provides a quick code sample to perform this kind of basic number lookup.

While this functionality is free, a carrier lookup costs $0.005 per request, but by including one extra parameter, it provides more information, including whether a number is capable of receiving an SMS or MMS message. Looking up a number that doesn’t exist produces a 404 response, the author provides this code as well and it can be used anytime you want to see if a phone number is valid or not.

For businesses that rely on telecommunications, this Lookup API acts like a REST API phonebook, and at the bottom of the tutorial are links to other tutorials for validating phone numbers in Python, PHP and Ruby respectively.

Be sure to read the next Messaging article: How to Use Message Brokering to Choreograph Microservices

Original Article

How to Validate Phone numbers in Node/JavaScript with the Twilio Lookup API

 

Comments