Phone Validator Template
- Next.js
- TypeScript
Check any phone number: real or not, mobile or landline, where it is, the time there and every format.
A Next.js app that checks and formats phone numbers. Enter a number with a country, or with a + code, and see whether it’s valid, whether it’s a mobile, landline or VoIP line, where it is and what time it is there, plus the number in international, national, E.164 and tel: formats with copy buttons. Use it as a contact-cleanup tool, or lift the API route to validate numbers in your own sign-up or CRM.

What it does
- Valid, and what kind
- Says whether the number is real and if it’s a mobile, landline, VoIP or toll-free line, with disposable numbers flagged.
- Where and when
- Shows the place and the local time there, with a note on whether it’s a good time to call.
- Every format
- International, national, E.164 for databases and a tel: link, each with a copy button.
- Any country
- Pick a country for local numbers, or start with + and the number’s own code is used.
- Keeps your key private
- The browser only talks to your own API route, which checks the input, caches answers and limits each visitor to 10 checks a minute.
How it works
The API route: it checks the number and country, then calls Phone Number Validator.
/** GET /api/validate?number=...&country=us: checks and formats a phone number. */
export async function GET(request: Request) {
const params = new URL(request.url).searchParams;
const number = str(params.get('number'), 40);
const country = str(params.get('country'), 2).toLowerCase();
if (!number) return fail('Enter a phone number');
if (!/^[+\d\s().-]{4,}$/.test(number)) return fail('A phone number can only have digits, spaces, + ( ) . and -');
if (country && !/^[a-z]{2}$/.test(country)) return fail('Country must be a 2-letter code, like us');
const key = `validate:${number.replace(/[^\d+]/g, '')}:${country}`;
const hit = fromCache<PhoneResult>(key, TTL_MS);
if (hit) return Response.json(hit);
const blocked = guard(request);
if (blocked) return blocked;
return respond(async () => {
// A number starting with + carries its own country; otherwise the selected country is used.
const query: Record<string, string> = { number };
if (country && !number.startsWith('+')) query.country = country;
const data = await callApi<PhoneResult>('phonenumbervalidator', { query });
toCache(key, data);
return data;
});
}Deploy it
- Get a free API key
The free plan includes 200 credits a month, no card needed. Create your key.
- Deploy it
Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for
APIVERVE_API_KEY: paste your key there. - Open your app
Vercel builds it and gives you a live URL, usually in about a minute. Every push to the repo redeploys it.
Try the Phone Number Validator API — the call this template makes
No key required to try it. Get a key to use it in your app.
{
"status": "ok",
"error": null,
"data": {
"country": "US",
"detectedCountry": "US",
"countryName": "United States",
"countrycode": 1,
"numberNational": 8165551017,
"extension": null,
"isValid": true,
"isMobile": true,
"isVoip": false,
"isDisposable": false,
"type": "fixed_line_or_mobile",
"isValidNumber": true,
"nationalSignificantNumber": "8165551017",
"location": "Missouri",
"carrier": null,
"timezones": [
"America/Chicago"
],
"formatted": {
"international": "+1 816-555-1017",
"national": "(816) 555-1017",
"rfc": "tel:+1-816-555-1017",
"e164": "+18165551017"
},
"riskScore": 0,
"riskLevel": "low"
}
}