Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Lookup v1 Tutorial: Validation and Formatting


(warning)

Warning

Version 2 of the Lookup API is now available! Lookup v2 has an improved developer experience and exciting features, such as Twilio Regions support and these new data packages:

  • Line Type Intelligence : Get the line type of a phone number including mobile, landline, fixed VoIP, non-fixed VoIP, toll-free, and more.
  • SIM Swap : Get information on the last SIM change for a mobile phone number.
  • Call Forwarding : Get the unconditional call forwarding status of a mobile phone number.
  • Identity Match : Get confirmation of ownership for a mobile phone number by comparing user-provided information against authoritative phone-based data sources.

You are currently viewing Version 1 content. Lookup v1 will be maintained for the time being, but any new features and development will be on v2. We strongly encourage you to do any new development with Lookup v2. Check out the migration guide(link takes you to an external page) or the API v2 Reference for more information.

Twilio Lookup can help you check that phone numbers you receive from your users are real. It can also provide you with the local format of an international phone number.

This guide will show you how to perform both kinds of lookups. You can skip to the carrier and caller name guide to learn about other information Lookup can provide about a phone number.


Validate a national phone number

validate-a-national-phone-number page anchor

Given a national phone number and an ISO country code(link takes you to an external page), Lookup will confirm the phone number is valid and return the number in its E.164 format(link takes you to an external page).

Lookup with National Formatted Number

lookup-with-national-formatted-number page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.lookups.v1.phoneNumbers('(510) 867-5310')
_10
.fetch({countryCode: 'US'})
_10
.then(phone_number => console.log(phone_number.phoneNumber));

Output

_15
{
_15
"caller_name": null,
_15
"carrier": {
_15
"error_code": null,
_15
"mobile_country_code": "310",
_15
"mobile_network_code": "456",
_15
"name": "verizon",
_15
"type": "mobile"
_15
},
_15
"country_code": "US",
_15
"national_format": "(510) 867-5310",
_15
"phone_number": "(510) 867-5310",
_15
"add_ons": null,
_15
"url": "https://lookups.twilio.com/v1/PhoneNumbers/+15108675310"
_15
}

If the number is invalid, this request will return an HTTP 404 status code.

If you plan to store the phone number after validating, we recommend storing the full E.164 formatted number returned in the phone number field. Most other Twilio services require the E.164 format for phone numbers.


Format an International Phone Number

format-an-international-phone-number page anchor

If you send Lookup an internationally formatted phone number, you can get the correct national format for that phone number from the national format field.

Lookup with International Formatted Number

lookup-with-international-formatted-number page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.lookups.v1.phoneNumbers('+4402077651182')
_10
.fetch()
_10
.then(phone_number => console.log(phone_number.nationalFormat));

Output

_15
{
_15
"caller_name": null,
_15
"carrier": {
_15
"error_code": null,
_15
"mobile_country_code": null,
_15
"mobile_network_code": null,
_15
"name": "Vodafone Business Solutions",
_15
"type": "landline"
_15
},
_15
"country_code": "GB",
_15
"national_format": "020 7765 1182",
_15
"phone_number": "+4402077651182",
_15
"add_ons": null,
_15
"url": "https://lookups.twilio.com/v1/PhoneNumbers/+4402077651182"
_15
}

Though most other Twilio services require the E.164 formatted number, the national format is often better to display to end users.

Lookup can tell you even more about a phone number. Check out the carrier and caller name guide to learn how.


Rate this page: