# NTN and STRN

> Check the format of Pakistani National Tax Numbers (NTN) and Sales Tax Registration Numbers (STRN). A format check, not FBR verification.

Source: https://pakdatakit.dev/docs/tax/

`import { analyzeNTN, validateNTN, validateSTRN } from 'pakdatakit/tax'`

Checks the shape of a National Tax Number and a Sales Tax Registration Number. Individuals use their 13-digit CNIC as their NTN (since the Finance Act 2015). Companies and associations of persons have a 7-digit NTN, often written with an 8th check digit as `1234567-8`.

> **A format check, not FBR verification**
>
> FBR does not publish the check-digit algorithm for NTNs, or the check digit or meaning of the digit groups for STRNs. These functions check the format only. They do not tell you whether a number is registered with FBR.
## Examples

**TypeScript**

```ts
import { analyzeNTN, validateNTN, validateSTRN } from 'pakdatakit';

analyzeNTN('1234567-8');
// → {
//     "type": "business",
//     "digits": "12345678",
//     "formatted": "1234567-8"
//   }

analyzeNTN('35202-1234567-1');
// → {
//     "type": "individual",
//     "digits": "3520212345671",
//     "formatted": "35202-1234567-1"
//   }

validateNTN('12345');
// → false

validateSTRN('12-34-5678-901-23');
// → true
```

**Python**

```python
from pakdatakit import analyze_ntn, validate_ntn, validate_strn

analyze_ntn('1234567-8')
# → {
#     "type": "business",
#     "digits": "12345678",
#     "formatted": "1234567-8"
#   }

analyze_ntn('35202-1234567-1')
# → {
#     "type": "individual",
#     "digits": "3520212345671",
#     "formatted": "35202-1234567-1"
#   }

validate_ntn('12345')
# → False

validate_strn('12-34-5678-901-23')
# → True
```

**Dart**

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

analyzeNTN('1234567-8');
// → {
//     "type": "business",
//     "digits": "12345678",
//     "formatted": "1234567-8"
//   }

analyzeNTN('35202-1234567-1');
// → {
//     "type": "individual",
//     "digits": "3520212345671",
//     "formatted": "35202-1234567-1"
//   }

validateNTN('12345');
// → false

validateSTRN('12-34-5678-901-23');
// → true
```

**C#**

```csharp
using PakDataKit;

Tax.AnalyzeNtn("1234567-8");
// → {
//     "type": "business",
//     "digits": "12345678",
//     "formatted": "1234567-8"
//   }

Tax.AnalyzeNtn("35202-1234567-1");
// → {
//     "type": "individual",
//     "digits": "3520212345671",
//     "formatted": "35202-1234567-1"
//   }

Tax.ValidateNtn("12345");
// → false

Tax.ValidateStrn("12-34-5678-901-23");
// → true
```

**PHP**

```php
use PakDataKit\Tax;

Tax::analyzeNtn('1234567-8');
// → {
//     "type": "business",
//     "digits": "12345678",
//     "formatted": "1234567-8"
//   }

Tax::analyzeNtn('35202-1234567-1');
// → {
//     "type": "individual",
//     "digits": "3520212345671",
//     "formatted": "35202-1234567-1"
//   }

Tax::validateNtn('12345');
// → false

Tax::validateStrn('12-34-5678-901-23');
// → true
```

## Reference

### analyzeNTN()

```ts
function analyzeNTN(ntn: string): NTNInfo | null;

type NTNType = 'individual' | 'business';

interface NTNInfo {
  type: NTNType;
  digits: string; // 7, 8 or 13 digits, without separators
  formatted: string; // 1234567-8, or #####-#######-# for a CNIC
}
```

**Parameters.** `ntn`: an NTN in any common format. A CNIC is read as an individual's NTN; 7 digits, optionally followed by a check digit, as a business NTN.

**Returns** the type, the digits and a display form, or `null` when the format is not valid.

**Caveats.** FBR does not publish the check-digit algorithm, so the check digit is not verified.

**Related:** [`validateNTN()`](#validatentn), [CNIC](https://pakdatakit.dev/docs/cnic/).

### validateNTN()

```ts
function validateNTN(ntn: string): boolean;
```

**Parameters.** `ntn`: as for `analyzeNTN()`.

**Returns** `true` when the format is valid: a CNIC for individuals, or 7 digits (optionally followed by a check digit) for businesses.

**Related:** [`analyzeNTN()`](#analyzentn).

### validateSTRN()

```ts
function validateSTRN(strn: string): boolean;
```

**Parameters.** `strn`: 13 digits, with optional spaces or dashes.

**Returns** `true` when the format is valid.

**Caveats.** FBR does not publish a check-digit algorithm or the meaning of the digit groups, so this validates the format only.

**Related:** [Sales tax](https://pakdatakit.dev/docs/salestax/), [FBR Digital Invoicing](https://pakdatakit.dev/docs/fbr-invoice/).

## Related

- [CNIC](https://pakdatakit.dev/docs/cnic/): the number individuals use as their NTN.
- [Income tax](https://pakdatakit.dev/docs/incometax/) and [sales tax](https://pakdatakit.dev/docs/salestax/).
- [API reference for `pakdatakit/tax`](https://pakdatakit.dev/api/typescript/tax/).
