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.
_10curl -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.
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.
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
_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
_10const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10const authToken = process.env.TWILIO_AUTH_TOKEN;
_10const client = require('twilio')(accountSid, authToken);
_10client.lookups.v2.phoneNumbers('+141599299600')
_10 .then(phone_number => console.log(phone_number.nationalFormat));
_18 "calling_country_code": "1",
_18 "country_code": "US",
_18 "phone_number": "+141599299600",
_18 "national_format": "(415) 992-9960",
_18 "validation_errors": null,
_18 "call_forwarding": 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"
Too long
_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
_10const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10const authToken = process.env.TWILIO_AUTH_TOKEN;
_10const client = require('twilio')(accountSid, authToken);
_10client.lookups.v2.phoneNumbers('+141599299600')
_10 .then(phone_number => console.log(phone_number.valid));
_20 "calling_country_code": null,
_20 "country_code": null,
_20 "phone_number": "+141599299600",
_20 "national_format": null,
_20 "validation_errors": [
_20 "call_forwarding": 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"