Need to validate phone numbers in your application? This guide covers everything you need to know about phone number validation via API, including international formats, E.164 standardization, and implementation examples in multiple languages.
What is Phone Number Validation?
Phone number validation verifies that a phone number is correctly formatted and potentially valid for a given country. This includes checking the country code, area code, and number length according to the ITU-T standards and country-specific rules.
A typical E.164 format looks like this: +14155552671
Phone Number Formats
Phone numbers can be represented in several formats:
E.164 (International Standard)
The universal format: +[country code][subscriber number]. Maximum 15 digits. Example: +14155552671
National Format
Local format without country code. Example: (415) 555-2671 (US)
International Format
Includes country code with formatting. Example: +1 415-555-2671
Using the Phone Validator API
TinyFn provides a simple endpoint to validate phone numbers:
GET https://api.tinyfn.io/v1/validate/phone?number=+14155552671
Headers: X-API-Key: your-api-key
{
"valid": true,
"number": "+14155552671",
"e164": "+14155552671",
"national_format": "(415) 555-2671",
"international_format": "+1 415-555-2671",
"country_code": "1",
"country": "US",
"line_type": "mobile",
"carrier": "Verizon"
}
Parameters
| Parameter | Type | Description |
|---|---|---|
number |
string | Phone number to validate (required) |
country |
string | ISO country code for national numbers (optional) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/validate/phone?number=%2B14155552671',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const result = await response.json();
console.log(result.valid); // true
console.log(result.line_type); // "mobile"
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/validate/phone',
params={'number': '+14155552671'},
headers={'X-API-Key': 'your-api-key'}
)
result = response.json()
print(result['valid']) # True
print(result['line_type']) # "mobile"
cURL
curl "https://api.tinyfn.io/v1/validate/phone?number=%2B14155552671" \
-H "X-API-Key: your-api-key"
Common Use Cases
- User Registration: Validate phone numbers during signup
- SMS Verification: Ensure numbers can receive SMS before sending codes
- Contact Forms: Validate customer phone numbers in forms
- CRM Data: Clean and standardize phone number databases
- Marketing: Verify phone numbers before SMS campaigns
Best Practices
- Store in E.164: Always store phone numbers in E.164 format
- Accept flexible input: Let users enter numbers in any format
- Show formatted output: Display numbers in user-friendly format
- Validate for purpose: Check line type if SMS is required
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-validate": {
"url": "https://api.tinyfn.io/mcp/validate/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all validation tools available via MCP in our Validation MCP Tools for AI Agents guide.
Try the Phone Validator API
Get your free API key and start validating phone numbers in seconds.
Get Free API Key