# Phone Number Validator & Formatter (libphonenumber) (`oqen/phone-number-validator`) Actor

Validate and format phone numbers for 240+ countries with Google's libphonenumber data: E.164, international and national formats, mobile/landline type, original carrier, location, time zones. Extract numbers from text. Offline, no lookups.

- **URL**: https://apify.com/oqen/phone-number-validator.md
- **Developed by:** [oqen](https://apify.com/oqen) (community)
- **Categories:** Lead generation, Developer tools, Business
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.50 / 1,000 phone number validateds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Phone Number Validator & Formatter (libphonenumber)

Clean up phone numbers from a CRM export, a lead list or a sign-up form. Every number is parsed with **Google's libphonenumber metadata** (via `libphonenumber-js`, the `max` dataset) and returned in standard formats with its type, country, original carrier, location and time zones.

Everything runs **offline inside the Actor**: no HLR lookups, no calls or SMS, no "who owns this number" databases. It is fast and cheap, and it doesn't touch personal data beyond what you send it.

### What you get for each number

| Field | Example |
|---|---|
| `status` / `reason` | `valid`, or `invalid` with `too_short`, `too_long`, `not_a_valid_number_for_region`, `needs_country_code_or_default_country`, `not_a_number` |
| `e164` | `+14155552671`, the format Twilio, WhatsApp and most CRMs want |
| `international` / `national` / `rfc3966` | `+1 415 555 2671` / `(415) 555-2671` / `tel:+14155552671` |
| `type` | `MOBILE`, `FIXED_LINE`, `FIXED_LINE_OR_MOBILE`, `TOLL_FREE`, `VOIP`, `PREMIUM_RATE`, `SHARED_COST`, `PAGER`, `UAN`, ... |
| `country`, `countryName`, `countryCode` | `US`, `United States`, `+1` |
| `carrier` | Network the number range was **originally** assigned to, e.g. `Vodafone`. Numbers can be ported, so treat this as a hint. |
| `location` | City or region from the prefix (`San Francisco, CA`, `London`) when it's more specific than the country |
| `timeZones` | `["America/Los_Angeles"]`, handy for scheduling calls |
| `extension` | `99` from `+1 415 555 2671 ext. 99` |

### Messy input is fine

- `00` and US `011` international prefixes are converted to `+`
- The UK-style `+44 (0)20...` trunk zero is removed
- `tel:` links, dashes, dots, brackets, non-breaking characters and extensions are handled
- Numbers without a country code are parsed with your **defaultCountry**
- **Extract from text**: paste a page or an email thread and every phone number in it is found and validated

### Input example

```json
{ "phoneNumbers": ["(415) 555-2671", "00351 912 345 678", "+44 (0)20 7946 0000"], "defaultCountry": "US" }
```

### Output example

```json
{ "input": "00351 912 345 678", "valid": true, "status": "valid", "e164": "+351912345678", "international": "+351 912 345 678",
  "national": "912 345 678", "rfc3966": "tel:+351912345678", "countryCode": "+351", "country": "PT", "countryName": "Portugal",
  "type": "MOBILE", "carrier": "Vodafone", "location": null, "timeZones": ["Atlantic/Azores", "Europe/Lisbon"] }
```

### Accuracy

The test suite cross-checks 2,019 numbers across all 245 regions (fixed line, mobile, toll-free and truncated variants) against Google's reference `google-libphonenumber`. They agree on validity, E.164 and type for 99.85%. The three differences come from small metadata version gaps (Saint Helena number types, one Paraguay range).

"Valid" means the number matches the official numbering plan for its country. It does **not** prove that the line is currently connected.

### Pricing

Pay per event: one `phone-validated` event per number returned. Duplicates, blank and non-numeric rows (`not_a_number`), and numbers dropped by `onlyValid` or `maxNumbers` are free. 100,000 numbers usually take under a minute.

# Actor input Schema

## `phoneNumbers` (type: `array`):

Numbers in any format: +351 912 345 678, 0044 20 7946 0000, (415) 555-2671, tel: links...

## `phoneNumbersText` (type: `string`):

One number per line (e.g. a column copied from a spreadsheet).

## `extractFromText` (type: `string`):

Optional. Paste text (an email signature, a web page's contact section) and every phone number in it is found and validated.

## `defaultCountry` (type: `string`):

Two-letter code used for numbers written without +country code, e.g. US, GB, PT, DE, BR. Leave empty if all numbers are international.

## `includeCarrierAndLocation` (type: `boolean`):

From Google's offline prefix data. Carrier is the network the number range was originally assigned to; ported numbers may have moved.

## `deduplicate` (type: `boolean`):

Numbers that normalise to the same E.164 value are returned and charged once.

## `onlyValid` (type: `boolean`):

Drop invalid numbers from the dataset (they are then not charged either).

## `maxNumbers` (type: `integer`):

Safety cap; extra numbers are skipped and not charged.

## Actor input object example

```json
{
  "phoneNumbers": [
    "+1 (415) 555-2671",
    "00351 912 345 678",
    "+44 (0)20 7946 0000",
    "020 7946 0000",
    "12345"
  ],
  "includeCarrierAndLocation": true,
  "deduplicate": true,
  "onlyValid": false,
  "maxNumbers": 50000
}
```

# Actor output Schema

## `results` (type: `string`):

One item per number: status, reason, E.164 / international / national / RFC 3966 formats, type, country, carrier, location, time zones.

## `summary` (type: `string`):

Counts of valid, invalid and duplicate numbers.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "phoneNumbers": [
        "+1 (415) 555-2671",
        "00351 912 345 678",
        "+44 (0)20 7946 0000",
        "020 7946 0000",
        "12345"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("oqen/phone-number-validator").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "phoneNumbers": [
        "+1 (415) 555-2671",
        "00351 912 345 678",
        "+44 (0)20 7946 0000",
        "020 7946 0000",
        "12345",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("oqen/phone-number-validator").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "phoneNumbers": [
    "+1 (415) 555-2671",
    "00351 912 345 678",
    "+44 (0)20 7946 0000",
    "020 7946 0000",
    "12345"
  ]
}' |
apify call oqen/phone-number-validator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,oqen/phone-number-validator"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/SjEbY2BJ5g1Hqdj25/builds/BSH2g9inXzcBrosvV/openapi.json
