Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Lookup v1 Tutorial: Validation and Formatting


(warning)

Warning

This is legacy Lookup v1 content. Use Lookup v2 for all new development.

Lookup v1 is in maintenance mode: it receives no new features and all ongoing development will happen in v2. If you're starting a new integration, you should use Lookup v2, not v1.

Lookup v2 has an improved developer experience and new features, such as Twilio Regions support and these 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. Includes 13 new line types for more accurate results compared to 3 line types in Lookup v1.
  • SIM Swap: Get information on the last SIM change for 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.

Check out the migration guide(link takes you to an external page) or the Lookup v2 API Reference to move over.

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).

(warning)

Warning

This is Lookup v1 (legacy) code. Lookup v1 is in maintenance mode and receives no new features. For new development, use the Lookup v2 API instead — start with the Lookup v2 Quickstart.

Lookup with National Formatted NumberLink to code sample: Lookup with National Formatted Number
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchPhoneNumber() {
11
const phoneNumber = await client.lookups.v1
12
.phoneNumbers("(510)867-5310")
13
.fetch({ countryCode: "US" });
14
15
console.log(phoneNumber.phoneNumber);
16
}
17
18
fetchPhoneNumber();

Response

Note about this response
1
{
2
"caller_name": null,
3
"carrier": null,
4
"add_ons": null,
5
"country_code": "US",
6
"national_format": "(510) 867-5310",
7
"phone_number": "(510)867-5310",
8
"url": "https://lookups.twilio.com/v1/PhoneNumbers/+15108675310"
9
}

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.

(warning)

Warning

This is Lookup v1 (legacy) code. Lookup v1 is in maintenance mode and receives no new features. For new development, use the Lookup v2 API instead — start with the Lookup v2 Quickstart.

Lookup with International Formatted NumberLink to code sample: Lookup with International Formatted Number
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchPhoneNumber() {
11
const phoneNumber = await client.lookups.v1
12
.phoneNumbers("+4402077651182")
13
.fetch();
14
15
console.log(phoneNumber.nationalFormat);
16
}
17
18
fetchPhoneNumber();

Response

Note about this response
1
{
2
"caller_name": null,
3
"carrier": {
4
"error_code": null,
5
"mobile_country_code": null,
6
"mobile_network_code": null,
7
"name": "Vodafone Business Solutions",
8
"type": "landline"
9
},
10
"country_code": "GB",
11
"national_format": "020 7765 1182",
12
"phone_number": "+4402077651182",
13
"add_ons": null,
14
"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.