validate_phone
Validate and verify phone numbers globally, confirming their format, location, carrier, and type. Supports over 190 countries for accurate number analysis and detailed results.
Instructions
Validates a phone number using Abstract API's Phone Validation service.
This function checks the validity and other details of phone numbers from over 190 countries.
It returns detailed information about the phone number including format, country, location,
type, and carrier information.
Args:
phone (str): The phone number to validate and verify.
country (str, optional): The country's ISO code to indicate the phone number's country.
This helps the API append the corresponding country code to its analysis.
For example, use "US" for United States numbers.
Returns:
dict[str, Any]: A dictionary containing detailed validation results. The dictionary
includes the following keys:
- "phone" (str): The phone number submitted for validation.
- "valid" (bool): True if the phone number is valid, False otherwise.
- "format" (dict): Object containing international and local formats.
- "international" (str): International format with country code and "+" prefix.
- "local" (str): Local/national format without international formatting.
- "country" (dict): Object containing country details.
- "code" (str): Two-letter ISO 3166-1 alpha-2 country code.
- "name" (str): Name of the country where the phone number is registered.
- "prefix" (str): Country's calling code prefix.
- "location" (str): Location details (region, state/province, sometimes city).
- "type" (str): Type of phone number. Possible values: "Landline", "Mobile",
"Satellite", "Premium", "Paging", "Special", "Toll_Free", "Unknown".
- "carrier" (str): The carrier that the number is registered with.
Example:
>>> await validate_phone("14152007986")
{
"phone": "14152007986",
"valid": true,
"format": {
"international": "+14152007986",
"local": "(415) 200-7986"
},
"country": {
"code": "US",
"name": "United States",
"prefix": "+1"
},
"location": "California",
"type": "mobile",
"carrier": "T-Mobile USA, Inc."
}
>>> await validate_phone("2007986", "US")
# Will validate with US country context
Raises:
ValueError: If the API key is not found in the environment variables.
requests.exceptions.HTTPError: If the API request fails (e.g., 4xx or 5xx error).
Exception: For any other unexpected errors.
Input Schema
Name | Required | Description | Default |
---|---|---|---|
country | No | ||
phone | Yes |
Input Schema (JSON Schema)
{
"properties": {
"country": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Country"
},
"phone": {
"title": "Phone",
"type": "string"
}
},
"required": [
"phone"
],
"title": "validate_phoneArguments",
"type": "object"
}