BusinessPhone Validation
Phone Number Validation API: Validate and Format Numbers in Python
Phone number validation API guide: validate and format numbers to E.164 in Python, tell mobiles from landlines, clean CRM lists in bulk, extract from text.
Phone numbers arrive in every shape a human can type: 06 12-34.56.78, +44 (0)20 7946 0958, 0044 20 7946 0958, (415) 555-2671 x204. Stored as typed, they break SMS sends, deduplication and call routing. Validated with a regular expression, they let impossible numbers through and reject real ones, because each country has its own lengths, prefixes and number ranges.
A phone number validation API checks a number against its country's numbering plan and returns it in a canonical format. This article explains how international numbers are structured and why regexes fail, then uses the Phone Number Validation API from Python to validate single numbers, clean a list in bulk, and pull every phone number out of a block of text, with the line type, carrier and time zone of each.
How phone numbers are built: E.164 and national formats
The international standard is ITU-T E.164: a +, a country calling code of 1 to 3 digits, then the national significant number, 15 digits at most in total. Every other way of writing the number is a local habit.
| Written as | What it is | E.164 |
|---|---|---|
020 7946 0958 |
UK national format, with the trunk prefix 0 |
+442079460958 |
0044 20 7946 0958 |
International format dialled from Europe (00 exit code) |
+442079460958 |
011 44 20 7946 0958 |
The same, dialled from the US or Canada (011 exit code) |
+442079460958 |
06 12 34 56 78 |
French national format | +33612345678 |
(650) 253-0000 |
North American national format | +16502530000 |
Three rules cause most bugs:
- The trunk prefix disappears. The
0of020or06is dialled only inside the country.+44 020...is a common and wrong mix. - A national number has no country.
06 12 34 56 78is a valid French mobile and nothing else; the same digits mean something different, or nothing, elsewhere. Without a country, no validator can decide. - Lengths and ranges vary by country and by range. A French number has 9 digits after the trunk prefix, a German one varies by area code, and inside a country only some prefixes are assigned. "10 to 15 digits" accepts millions of numbers that cannot exist.
Google maintains the reference metadata for all of this in libphonenumber, the library behind Android's dialler, and updates it as regulators open new ranges. The API runs it on every call, together with handling for the inputs people actually type (00 and 011 prefixes, extensions, vanity numbers, tel: links).
Validate a phone number with Python
GET /v1/phone/validate takes number and, for national numbers, country (ISO 3166 two-letter code). The examples use Python and requests; the API reference lists every field.
import requests
HOST = "phone-number-validation-type-carrier-timezone.p.rapidapi.com"
API = f"https://{HOST}"
HEADERS = {"x-rapidapi-key": "YOUR_API_KEY", "x-rapidapi-host": HOST}
def validate(number: str, country: str | None = None) -> dict:
params = {"number": number}
if country:
params["country"] = country
response = requests.get(
f"{API}/v1/phone/validate", headers=HEADERS, params=params, timeout=15
)
response.raise_for_status()
return response.json()
result = validate("+44 20 7946 0958")
print(result["valid"], result["e164"], result["line_type"])
With curl (the + and spaces are URL-encoded):
curl "https://phone-number-validation-type-carrier-timezone.p.rapidapi.com/v1/phone/validate?number=%2B44%2020%207946%200958" \
-H "x-rapidapi-key: YOUR_API_KEY" \
-H "x-rapidapi-host: phone-number-validation-type-carrier-timezone.p.rapidapi.com"
The real response:
{
"input": "+44 20 7946 0958",
"valid": true,
"possible": true,
"reason": "Valid fixed line number in United Kingdom.",
"e164": "+442079460958",
"international": "+44 20 7946 0958",
"national": "020 7946 0958",
"country_code": 44,
"region": "GB",
"country": "United Kingdom",
"location": "London",
"line_type": "fixed_line",
"timezones": ["Europe/London"]
}
possible checks the length only; valid checks that the number falls in a range the country actually uses. Store e164 as the key (it is what SMS gateways and dialers expect), and show international or national to people.
National numbers need a country
The same French mobile, first without a country, then with country=FR. Both are real calls:
{
"input": "06 12 34 56 78",
"valid": false,
"possible": false,
"reason": "No country: add +country code or the country parameter.",
"line_type": "unknown",
"timezones": []
}
{
"input": "06 12 34 56 78",
"valid": true,
"possible": true,
"reason": "Valid mobile number in France.",
"e164": "+33612345678",
"international": "+33 6 12 34 56 78",
"national": "06 12 34 56 78",
"country_code": 33,
"region": "FR",
"country": "France",
"line_type": "mobile",
"carrier": "SFR",
"timezones": ["Europe/Paris"]
}
In a sign-up form, pass the country the user selected, or the one you infer from their address or IP. Numbers that start with +, 00 or 011 are read on their own and ignore country. An unknown country code is the only input error: country=XX returns 400 invalid_country, unbilled.
Extensions are kept apart
Business numbers often carry an extension. +1 (415) 555-2671 ext. 204 comes back with a clean E.164 and the extension in its own field:
{
"input": "+1 (415) 555-2671 ext. 204",
"valid": true,
"e164": "+14155552671",
"international": "+1 415-555-2671 ext. 204",
"national": "(415) 555-2671 ext. 204",
"extension": "204",
"country": "United States",
"location": "San Francisco, CA",
"line_type": "fixed_line_or_mobile",
"timezones": ["America/Los_Angeles"]
}
Mobile or landline: reading the line type
line_type decides what you can do with a number:
line_type |
Meaning | Typical action |
|---|---|---|
mobile |
Mobile phone | SMS and WhatsApp |
fixed_line |
Landline | Calls only; do not send SMS |
fixed_line_or_mobile |
Either: the country does not separate them | Allow SMS, expect some failures |
toll_free |
Free to call (0800, 1-800) | Business numbers, never a person's mobile |
premium_rate, shared_cost |
Paid numbers | Usually reject in sign-up forms |
voip |
Internet telephony | Accept, or flag for fraud review |
personal_number, pager, uan, voicemail |
Special ranges | Case by case |
The US and Canada are the main fixed_line_or_mobile case: in the North American Numbering Plan, mobiles and landlines share area codes and exchanges, so no offline check can tell them apart, and the original carrier is not published either. Elsewhere, carrier gives the operator that was assigned the number range: SFR above, Airtel and Optus in the bulk example below. A number ported to another operator keeps showing its original carrier.
Bulk phone validation for a CRM import
POST /v1/phone/validate/bulk takes up to 100 numbers with one default country, and returns them in order with a summary. A real call with eight inputs from a French CRM export:
numbers = [
"06 12 34 56 78",
"0044 20 7946 0958",
"+1 650-253-0000",
"1-800-FLOWERS",
"+91 98765 43210",
"+61 412 345 678",
"06 12 34 56",
"112",
]
response = requests.post(
f"{API}/v1/phone/validate/bulk",
headers=HEADERS,
json={"numbers": numbers, "country": "FR"},
timeout=30,
)
batch = response.json()
print(batch["summary"]) # {'valid': 5, 'invalid': 3}
The response, trimmed to the fields that tell the story:
{
"results": [
{ "input": "06 12 34 56 78", "valid": true, "e164": "+33612345678", "line_type": "mobile", "carrier": "SFR" },
{ "input": "0044 20 7946 0958", "valid": true, "e164": "+442079460958", "line_type": "fixed_line", "location": "London" },
{ "input": "+1 650-253-0000", "valid": true, "e164": "+16502530000", "line_type": "fixed_line_or_mobile", "location": "Mountain View, CA" },
{ "input": "1-800-FLOWERS", "valid": false, "reason": "Not a possible number for this country (wrong length).", "region": "FR" },
{ "input": "+91 98765 43210", "valid": true, "e164": "+919876543210", "line_type": "mobile", "carrier": "Airtel", "timezones": ["Asia/Kolkata"] },
{
"input": "+61 412 345 678",
"valid": true,
"line_type": "mobile",
"carrier": "Optus",
"timezones": ["Australia/Adelaide", "Australia/Brisbane", "Australia/Eucla", "Australia/Lord_Howe", "Australia/Perth", "Australia/Sydney"]
},
{ "input": "06 12 34 56", "valid": false, "reason": "Not a possible number for this country (wrong length)." },
{ "input": "112", "valid": false, "reason": "Emergency number, not a subscriber line." }
],
"summary": { "valid": 5, "invalid": 3 }
}
The call used 8 credits, one per number, invalid ones included. Three results deserve a closer look:
1-800-FLOWERSis invalid here because the default country is France. Asked alone withcountry=US, it is atoll_freenumber,+18003569377. In a mixed list, pass the country per record (one bulk call per country) rather than one default for everything.- The Australian mobile has six time zones. Australian mobiles are not tied to a state, so the number could be anywhere from Perth to Lord Howe Island. Zones of other countries or territories that share the numbering range are left out: a US toll-free number lists the 11 US zones, from
Pacific/HonolulutoAmerica/New_York, not the Caribbean islands that share the +1 code. - Time zone names are the canonical IANA ones, such as
Asia/Kolkatarather than the older aliasAsia/Calcutta, so you can compare them as strings.
If you plan to send SMS by local time, those multi-zone answers matter: the SMS send time guide shows how to compute a slot that is daytime in every possible zone.
A cleaning pass then keeps what each channel needs:
def clean(results: list[dict]) -> dict[str, list[str]]:
keep = {"sms": [], "call": [], "rejected": []}
for r in results:
if not r["valid"]:
keep["rejected"].append(r["input"])
elif r["line_type"] in ("mobile", "fixed_line_or_mobile"):
keep["sms"].append(r["e164"])
elif r["line_type"] in ("fixed_line", "toll_free", "voip"):
keep["call"].append(r["e164"])
else:
keep["rejected"].append(r["input"])
return keep
Email columns in the same import deserve the same pass; the email verification guide covers typos, disposable domains and dead mail servers.
Extract phone numbers from text
POST /v1/phone/extract finds every phone number in a text of up to 20,000 characters, validates each one and returns them in order, without duplicates, with their position. A real call on a support email footer full of things that look like numbers:
text = (
"Thanks for your order #4417-2026 (EUR 129.90, 12/11/2026). Questions? "
"Call our support on +44 20 7946 0958 (Mon-Fri) or the Paris office: "
"01 23 45 67 89. US customers: 1-800-FLOWERS, x204 for returns. "
"Fax: +33 1 23 45 67 90. SIRET 794 598 813 00077."
)
response = requests.post(
f"{API}/v1/phone/extract",
headers=HEADERS,
json={"text": text, "country": "FR"},
timeout=30,
)
for n in response.json()["numbers"]:
print(n["start"], n["e164"], n["line_type"])
{
"numbers": [
{ "input": "+44 20 7946 0958", "valid": true, "e164": "+442079460958", "line_type": "fixed_line", "location": "London", "start": 90 },
{ "input": "01 23 45 67 89", "valid": true, "e164": "+33123456789", "line_type": "fixed_line", "start": 138 },
{ "input": "+33 1 23 45 67 90", "valid": true, "e164": "+33123456790", "line_type": "fixed_line", "start": 206 }
],
"count": 3
}
The order number, the price, the date and the 14-digit SIRET company number were left alone. 1-800-FLOWERS was not picked up either: with France as the default country it is not a possible number, the same result as in bulk. The call used 3 credits, one per number found. start is the character offset, useful to highlight or mask the numbers in the original text.
Bulk lists without code on Apify
For a one-off spreadsheet, the same engine runs as an Apify Actor, Phone Number Validator - Bulk E.164, Carrier & Timezone: paste numbers, set a default country, and download one row per number as CSV or Excel. It costs $0.0005 per number validated, and the Apify free plan covers 200 numbers per run.
What it costs
1 credit per number: one per validation, one per number in bulk, one per number found by extraction (1 minimum). An invalid number is a normal answer and counts; failed calls (4xx, 5xx) use no credits.
| Plan | Price per month | Credits | In practice |
|---|---|---|---|
| BASIC | Free | 10 per day | 10 numbers a day to test |
| PRO | $3.99 | 20,000 | about $0.0002 per number |
| ULTRA | $9.99 | 150,000 | about $0.00007 per number |
| MEGA | $29.99 | 1,000,000 | about $0.00003 per number |
Beyond the monthly quota, paid plans continue at $0.002 per credit. In our market survey, phone lookup APIs on the RapidAPI Hub charged between $0.006 and $0.05 per number.
What the phone number validation API does not do
- No live line check. "Valid" means the number fits its country's numbering plan, not that it is switched on or assigned to someone. That needs an HLR lookup through the mobile network, a paid per-number service this API does not call.
- No porting data.
carrieris the operator the range was assigned to; a ported number keeps it. North American numbers have no carrier at all. - No owner lookup. The API returns nothing about who holds the number: no name, no address, no "reverse lookup".
- No SMS or call. It does not send a one-time code. To prove that a user owns a number, send an OTP through your SMS provider after validation.
- No spam or fraud score. Line type helps (premium rate, VoIP), but there is no reputation data.
Frequently asked questions
How do I validate a phone number in Python?
For a quick check, call GET /v1/phone/validate?number=...&country=... and read valid, e164 and line_type. If you prefer a local library, the phonenumbers package (the Python port of libphonenumber) does the core validation; you then maintain its updates and the input handling yourself.
What is the E.164 format?
The international format defined by ITU-T recommendation E.164: +, the country code, then the national number without its trunk prefix, 15 digits at most, no spaces. 020 7946 0958 in London is +442079460958. It is the format SMS gateways, dialers and most databases expect.
Can a phone number validation API tell if a number is a mobile?
Yes in most countries: line_type is mobile or fixed_line from the number range. In the US and Canada, mobiles and landlines share ranges, so the answer is fixed_line_or_mobile; only a paid carrier lookup can tell them apart there.
Does it check whether the number is active?
No. It checks the numbering plan, which catches typos, fake and impossible numbers. Whether a line is in service needs a network (HLR) lookup or a verification SMS.
How do I validate numbers that have no country code?
Pass country with the ISO code (FR, GB, US...). In bulk, country is the default for every number without a +, 00 or 011 prefix, so group mixed lists by country first.
Get started
Phone Number Validation API
Validate phone numbers from 240+ countries: valid, mobile or landline, carrier, timezone, E.164.
- Phone Validation
- Data Quality
- SMS
- Python
- CRM


