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

Formatting and Validation


Lookup's basic request is free to use and provides:

  • E.164 and national formats
  • Phone number validation including helpful errors

To make a free formatting and validation request, do not include any Fields in the request.


_10
curl -X GET "https://lookups.twilio.com/v2/PhoneNumbers/{PhoneNumber}" \ -u
_10
$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

Release Stage and Access: Public Beta, available via self-service.


Response properties

response-properties page anchor

Only valid numbers (for a given region, using length, and prefix information) will return results. If you attempt to lookup a phone number which is invalid, you will receive ”valid”: false in the response. In some cases you will also receive a reason for the validation failure in the validation_errors field.

Validation errors property values

type-property-values page anchor

The following are the possible values for the Validation Errors property.

  • TOO_SHORT
  • TOO_LONG
  • INVALID_BUT_POSSIBLE
  • INVALID_COUNTRY_CODE
  • INVALID_LENGTH
  • NOT_A_NUMBER

Lookup with valid E.164 phone number

lookup-with-valid-e164-phone-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.v2.phoneNumbers('+141599299600')
_10
.fetch()
_10
.then(phone_number => console.log(phone_number.nationalFormat));

Output

_18
{
_18
"calling_country_code": "1",
_18
"country_code": "US",
_18
"phone_number": "+141599299600",
_18
"national_format": "(415) 992-9960",
_18
"valid": true,
_18
"validation_errors": null,
_18
"caller_name": null,
_18
"sim_swap": null,
_18
"call_forwarding": null,
_18
"line_status": null,
_18
"line_type_intelligence": null,
_18
"identity_match": null,
_18
"reassigned_number": null,
_18
"sms_pumping_risk": null,
_18
"phone_number_quality_score": null,
_18
"url": "https://lookups.twilio.com/v2/PhoneNumbers/+14159929960"
_18
}

Lookup with invalid E.164 phone number

lookup-with-invalid-e164-phone-number page anchor

Too long

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.v2.phoneNumbers('+141599299600')
_10
.fetch()
_10
.then(phone_number => console.log(phone_number.valid));

Output

_20
{
_20
"calling_country_code": null,
_20
"country_code": null,
_20
"phone_number": "+141599299600",
_20
"national_format": null,
_20
"valid": false,
_20
"validation_errors": [
_20
"TOO_LONG"
_20
],
_20
"caller_name": null,
_20
"sim_swap": null,
_20
"call_forwarding": null,
_20
"line_status": null,
_20
"line_type_intelligence": null,
_20
"identity_match": null,
_20
"reassigned_number": null,
_20
"sms_pumping_risk": null,
_20
"phone_number_quality_score": null,
_20
"url": "https://lookups.twilio.com/v2/PhoneNumbers/+141599299600"
_20
}


Rate this page: