Skip to content

Landlines and special numbers

import { analyzeNumber, getNumberType, validateLandline, getAreaCode } from 'pakdatakit/numbers'

Identifies and formats any Pakistani telephone number: mobile, landline, UAN (111), toll-free (0800), premium-rate (0900) or personal (0122). For landlines and UANs it also gives the area code and the cities it serves.

analyzeNumber() Valid

Type
Landline
Formatted
042-35761234
E.164
+924235761234
Area code
042
Cities
Lahore
getAreaCode()
041
import { analyzeNumber, getNumberType, validateLandline, getAreaCode } from 'pakdatakit';
analyzeNumber('042 35761234');
// → {
// "type": "landline",
// "formatted": "042-35761234",
// "e164": "+924235761234",
// "areaCode": "042",
// "cities": [
// "Lahore"
// ]
// }
getNumberType('021-111-123-456');
// → 'uan'
validateLandline('051-2345678');
// → true
getAreaCode('Faisalabad');
// → '041'
function analyzeNumber(phone: string): NumberInfo | null;
type NumberType =
'mobile' | 'landline' | 'uan' | 'toll-free' | 'premium' | 'personal';
interface NumberInfo {
type: NumberType;
formatted: string; // national format, e.g. 021-111-825-888
e164: string | null; // e.g. +9221111825888
areaCode: string | null; // e.g. 021, for landlines and UANs
cities: string[]; // cities served by the area code, when known
}

Parameters. phone: a number in local or international format.

Returns the number details, or null if it is not a valid Pakistani number. formatted is the national format with the trunk prefix and separators.

Caveats.

  • e164 is null for a UAN dialled without an area code (111-123-456).
  • cities is filled only when the area code is known.
  • Number patterns come from Google libphonenumber’s PK metadata (v9.0.41).

Related: getNumberType(), analyzePhone() for mobile numbers only.

function getNumberType(phone: string): NumberType | null;

Parameters. phone: a number in local or international format.

Returns the number type, or null if it is not a valid Pakistani number.

Related: analyzeNumber().

function validateLandline(phone: string): boolean;

Parameters. phone: a number in local or international format, such as 042-35761234.

Returns true for a valid landline (fixed-line) number. Mobile numbers, UANs and toll-free numbers return false.

Related: validatePhone() for mobile numbers.

function getAreaCode(city: string): string | null;

Parameters. city: a city name, case-insensitive.

Returns the landline area code with the trunk prefix (for example "042"), or null if the city is not in the dataset.

Data. 114 area codes, from the numbering plan PTA sent to the ITU in November 2021, which lists every code with its district. Names are spelt as the districts in the library’s district list.

Related: analyzeNumber().

  • Phone: validate and format mobile numbers.
  • Networks: the original operator of a mobile prefix.
  • Quality: flags for landlines and made-up numbers given for a delivery.
  • API reference