Skip to content

Phone

import { validatePhone, formatPhone, analyzePhone } from 'pakdatakit/phone' · import { getNetwork } from 'pakdatakit/networks'

Accepts the forms people actually type (03…, +92…, 0092…, +92 (0) 3… and 3…, with spaces, dashes, dots or Urdu digits) and checks that the 03XX prefix belongs to a mobile operator.

analyzePhone() Valid

E.164
+923451234567
Original network
Telenor
import { validatePhone, formatPhone, analyzePhone, getNetwork } from 'pakdatakit';
validatePhone('0300-1234567');
// → true
formatPhone('0300 1234567');
// → '+923001234567'
analyzePhone('+92 345 1234567');
// → {
// "valid": true,
// "formatted": "+923451234567",
// "network": "Telenor"
// }
getNetwork('03211234567');
// → 'Jazz'
function validatePhone(phone: string): boolean;

Parameters. phone: a mobile number in any of the forms above.

Returns true for a mobile number with an allocated 03XX prefix. Landlines, UAN and toll-free numbers return false (see analyzeNumber() for those).

Related: formatPhone(), analyzePhone().

function formatPhone(phone: string): string | null;

Returns the number in E.164 form (+923001234567), or null when it is not a valid mobile number.

function analyzePhone(phone: string): PhoneAnalysis;
interface PhoneAnalysis {
valid: boolean;
formatted: string | null; // E.164
network: string; // 'Jazz' | 'Zong' | 'Ufone' | 'Telenor' | 'SCO' | 'Unknown'
}

Returns validity, the E.164 form and the original network in one call.

function getNetwork(phone: string): string;

Returns Jazz, Zong, Ufone, Telenor, SCO (0355, Azad Jammu and Kashmir and Gilgit-Baltistan) or Unknown.

Caveats. This is the network the prefix was first allocated to. Pakistan has mobile number portability, so a number may have moved to another operator since.

Related: createWhatsAppLink(), phoneRiskSignals().