npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pakistan-validators

v0.1.1

Published

Validate, parse, and format Pakistani CNIC numbers and mobile phone numbers. Zero dependencies, TypeScript-first.

Downloads

92

Readme

pakistan-validators

Validate, parse, and format Pakistani CNIC numbers and mobile phone numbers in JavaScript, TypeScript, and Node.js.

  • Zero dependencies, ~2 KB, tree-shakeable
  • TypeScript-first with full type definitions
  • Accepts messy input: dashes, spaces, +92/0092/92 prefixes, even Urdu (۰-۹) and Arabic-Indic (٠-٩) digits
  • Works in Node, browsers, and edge runtimes

Install

npm install pakistan-validators

Validate a CNIC number

import { parseCNIC, isValidCNIC, formatCNIC } from "pakistan-validators";

parseCNIC("3520212345671");
// {
//   valid: true,
//   normalized: "3520212345671",
//   formatted: "35202-1234567-1",
//   province: "Punjab",
//   gender: "male"
// }

isValidCNIC("35202-1234567-1"); // true
formatCNIC("۳۵۲۰۲۱۲۳۴۵۶۷۱");    // "35202-1234567-1"
formatCNIC("garbage");           // null

province comes from the first digit (NADRA region code) and gender from the parity of the last digit (odd = male, even = female).

Invalid input returns a reason instead of just false:

parseCNIC("352021234567");
// { valid: false, reason: "expected 13 digits, got 12" }

Validate a Pakistani mobile number

import { parsePhone, isValidPhone, formatPhone } from "pakistan-validators";

parsePhone("+92 300 1234567");
// {
//   valid: true,
//   e164: "+923001234567",
//   local: "0300-1234567",
//   international: "+92 300 1234567",
//   prefix: "300"
// }

formatPhone("03001234567", "e164");          // "+923001234567"
formatPhone("00923001234567");               // "0300-1234567"
formatPhone("03001234567", "international"); // "+92 300 1234567"

All common input shapes normalize to the same number: 03001234567, 0300-1234567, +923001234567, 923001234567, 00923001234567.

Validation covers the assigned mobile prefix ranges (0300–0349 and 0355). The package deliberately does not report a carrier: since mobile number portability, the prefix no longer reliably identifies the current network.

Why not just a regex?

The usual CNIC regex (^\d{5}-\d{7}-\d$) accepts invalid region codes and rejects real-world input that this package handles:

isValidCNIC("۳۵۲۰۲-۱۲۳۴۵۶۷-۱"); // true  — Urdu digits, common in copied text
isValidCNIC("3520212345671");    // true  — no dashes
isValidCNIC("95202-1234567-1");  // false — "9" is not a NADRA region code
isValidPhone("00923001234567");  // true  — 0092 prefix
isValidPhone("0399-1234567");    // false — unassigned prefix a regex happily accepts

A regex also can't tell you why input failed; parseCNIC and parsePhone return a reason you can show to the user.

API

| Function | Returns | | --- | --- | | parseCNIC(input) | { valid: true, normalized, formatted, province, gender } or { valid: false, reason } | | isValidCNIC(input) | boolean | | formatCNIC(input) | "35202-1234567-1" or null | | parsePhone(input) | { valid: true, e164, local, international, prefix } or { valid: false, reason } | | isValidPhone(input) | boolean | | formatPhone(input, style?) | string in "local" (default), "international", or "e164" style, or null |

License

MIT