Structural validation
Checks length, separators, province digit, family number patterns, and weighted mod-10 checksum.
NeedCatch typos before they hit your database.
ValueHigher-quality identity fields on first submit.
ProjectsCase Study

Forms across Pakistan collect CNIC numbers daily, but ad-hoc regex checks miss province digits, family-number rules, and checksum failures that erode data quality downstream.
verify-pak-nic packages those rules as a small, offline library—explicit about what it does (structural validation) and what it never claims (NADRA identity lookup).
Teams copy brittle regex from Stack Overflow, ship slightly different rules in web and API, and silently accept typos until reconciliation fails.
Bad CNIC capture wastes support time and breaks KYC-style flows before they start.
One library, multiple runtimes:
validateCNIC, parseCNIC, and hasValidChecksum expose structured reasons—not just boolean failures.
formatCNIC, stripCNIC, and maskCNIC keep display consistent without leaking full numbers in logs.
generateCNIC and generateIdentity help fixtures stay structurally valid in dev and QA.
Teams share one rule set across Node, browsers, and frameworks—with no network calls and no telemetry.
Checks length, separators, province digit, family number patterns, and weighted mod-10 checksum.
NeedCatch typos before they hit your database.
ValueHigher-quality identity fields on first submit.
parseCNIC returns province, gender, and administrative breakdown when digits are valid.
NeedDownstream UX can show human-readable region info offline.
ValueRicher forms without external APIs.
computeChecksumDigit in src/utils/checksum.ts applies mod-10 weighting on the first 12 digits—hasValidChecksum gates full 13-digit strings.
Business valueCatches transpositions simple regex misses.
sideEffects: false with separate ESM/CJS builds via tsup and explicit export maps for browser entry points.
Business valueDrop into Next.js or Node services without bloating client bundles.
| Challenge | Solution |
|---|---|
| Developers assumed the library performed government identity lookup—setting wrong expectations for compliance teams. | README and API docs state clearly: offline structural validation only, never NADRA verification. |
| Province and region tables needed to stay data-driven as administrative codes evolved. | Centralized province constants and parse.ts lookup paths so validation and parse stay aligned. |
verify-pak-nic is a small OSS case study: precise rules, honest scope, and packaging that respects privacy. If you want similar libraries for your domain, start a conversation.
Start a conversationOpen Source Author
Community library / verify-pak-nic
2026
Solo build
Next Project
Ask about projects, skills, or how to hire.