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
Examples
Section titled “Examples”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'from pakdatakit import validate_phone, format_phone, analyze_phone, get_network
validate_phone('0300-1234567')# → True
format_phone('0300 1234567')# → '+923001234567'
analyze_phone('+92 345 1234567')# → {# "valid": True,# "formatted": "+923451234567",# "network": "Telenor"# }
get_network('03211234567')# → 'Jazz'import 'package:pakdatakit/pakdatakit.dart';
validatePhone('0300-1234567');// → true
formatPhone('0300 1234567');// → '+923001234567'
analyzePhone('+92 345 1234567');// → {// "valid": true,// "formatted": "+923451234567",// "network": "Telenor"// }
getNetwork('03211234567');// → NetworkName.jazzusing PakDataKit;
Phone.Validate("0300-1234567");// → true
Phone.Format("0300 1234567");// → "+923001234567"
Phone.Analyze("+92 345 1234567");// → {// "valid": true,// "formatted": "+923451234567",// "network": "Telenor"// }
Networks.GetNetwork("03211234567");// → "Jazz"use PakDataKit\Networks;use PakDataKit\Phone;
Phone::validate('0300-1234567');// → true
Phone::format('0300 1234567');// → '+923001234567'
Phone::analyze('+92 345 1234567');// → {// "valid": true,// "formatted": "+923451234567",// "network": "Telenor"// }
Networks::getNetwork('03211234567');// → 'Jazz'Reference
Section titled “Reference”validatePhone()
Section titled “validatePhone()”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().
formatPhone()
Section titled “formatPhone()”function formatPhone(phone: string): string | null;Returns the number in E.164 form (+923001234567), or null when it is not a valid mobile number.
analyzePhone()
Section titled “analyzePhone()”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.
getNetwork()
Section titled “getNetwork()”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().