# Landlines and special numbers

> Identify and format any Pakistani phone number (mobile, landline, UAN, toll-free, premium or personal) and look up landline area codes.

Source: https://pakdatakit.dev/docs/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.

## Examples

**TypeScript**

```ts
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'
```

**Python**

```python
from pakdatakit import analyze_number, get_number_type, validate_landline, get_area_code

analyze_number('042 35761234')
# → {
#     "type": "landline",
#     "formatted": "042-35761234",
#     "e164": "+924235761234",
#     "area_code": "042",
#     "cities": [
#       "Lahore"
#     ]
#   }

get_number_type('021-111-123-456')
# → 'uan'

validate_landline('051-2345678')
# → True

get_area_code('Faisalabad')
# → '041'
```

**Dart**

```dart
import 'package:pakdatakit/pakdatakit.dart';

analyzeNumber('042 35761234');
// → {
//     "type": "landline",
//     "formatted": "042-35761234",
//     "e164": "+924235761234",
//     "areaCode": "042",
//     "cities": [
//       "Lahore"
//     ]
//   }

getNumberType('021-111-123-456');
// → NumberType.uan

validateLandline('051-2345678');
// → true

getAreaCode('Faisalabad');
// → '041'
```

**C#**

```csharp
using PakDataKit;

Numbers.Analyze("042 35761234");
// → {
//     "type": "landline",
//     "formatted": "042-35761234",
//     "e164": "+924235761234",
//     "areaCode": "042",
//     "cities": [
//       "Lahore"
//     ]
//   }

Numbers.GetNumberType("021-111-123-456");
// → NumberType.Uan

Numbers.ValidateLandline("051-2345678");
// → true

Numbers.GetAreaCode("Faisalabad");
// → "041"
```

**PHP**

```php
use PakDataKit\Numbers;

Numbers::analyze('042 35761234');
// → {
//     "type": "landline",
//     "formatted": "042-35761234",
//     "e164": "+924235761234",
//     "areaCode": "042",
//     "cities": [
//       "Lahore"
//     ]
//   }

Numbers::getNumberType('021-111-123-456');
// → 'uan'

Numbers::validateLandline('051-2345678');
// → true

Numbers::getAreaCode('Faisalabad');
// → '041'
```

## Reference

### analyzeNumber()

```ts
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()`](#getnumbertype), [`analyzePhone()`](https://pakdatakit.dev/docs/phone/#analyzephone) for mobile numbers only.

### getNumberType()

```ts
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()`](#analyzenumber).

### validateLandline()

```ts
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()`](https://pakdatakit.dev/docs/phone/#validatephone) for mobile numbers.

### getAreaCode()

```ts
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()`](#analyzenumber).

## Related

- [Phone](https://pakdatakit.dev/docs/phone/): validate and format mobile numbers.
- [Networks](https://pakdatakit.dev/docs/networks/): the original operator of a mobile prefix.
- [Quality](https://pakdatakit.dev/docs/quality/): flags for landlines and made-up numbers given for a delivery.
- [API reference](https://pakdatakit.dev/api/typescript/numbers/)
