nepali-id-validators-pro-max
v1.0.0
Published
🪪 Nepal ID format validators — citizenship, PAN, VAT, passport, driving license, national ID. Pure regex + parsers + canonical formatters with Devanagari-digit input tolerance.
Maintainers
Readme
nepali-id-validators-pro-max
नेपाली परिचय-पत्र — pro-max edition
Nepal ID format validators. Citizenship, PAN, VAT, passport, driving license, national ID — pure regex + parsers + canonical formatters with Devanagari-digit input tolerance.
✨ Highlights
- 🪪 All six common Nepal IDs — citizenship, PAN, VAT, passport (MRP + e-passport), driving license, NID
- 🔢 Devanagari digits accepted on every field —
१२३४५६७८९works as well as123456789 - 🧹 Format-agnostic input —
-,/, spaces, mixed Devanagari/ASCII all normalised - 📋 Parsers + formatters — get structured details and a canonical string
- 🔍
detectIDType— best-effort routing for KYC pipelines that accept "any Nepal ID" - 🚫 Format-only validation — we don't claim to verify issuance (that needs the relevant authority's database)
- 📦 Zero deps · ESM + CJS · TypeScript-first · tree-shakeable
📦 Install
npm install nepali-id-validators-pro-max
pnpm add nepali-id-validators-pro-max
yarn add nepali-id-validators-pro-max
bun add nepali-id-validators-pro-max⚡ Quick Start
import {
isValidCitizenship,
isValidPAN,
isValidVAT,
isValidPassport,
isValidDrivingLicense,
isValidNID,
detectIDType,
} from "nepali-id-validators-pro-max";
isValidCitizenship("12-01-78-12345"); // true
isValidPAN("301234567"); // true
isValidVAT("301234567"); // true (alias of PAN)
isValidPassport("M1234567"); // true (MRP, letter + digits)
isValidPassport("11936491"); // true (MRP, all-numeric)
isValidPassport("PA1234567"); // true (e-passport)
isValidDrivingLicense("12-04-12345678"); // true (district 12)
isValidNID("1234567890"); // true (10 bare digits)
detectIDType("PA1234567"); // "passport"
detectIDType("12-01-78-12345"); // "citizenship"
detectIDType("12-04-12345678"); // "driving-license" (8-digit sequence)🧠 Mental Model
| Rule | Why |
|---|---|
| Format only — never issuance. | Real verification needs CDO / IRD / DoP / DoTM / NIDMC databases. We do regex + structural checks. |
| Devanagari digits are normalised. | A user typing १२३ should validate identically to 123. |
| Separators are normalised (where used). | Citizenship and DL accept -, /, spaces; canonical output uses -. |
| DL and citizenship both use district code [1, 77]. | DL is disambiguated by sequence length (last group ≥ 7 digits); citizenship sequences are typically shorter. |
| NID is bare 10 digits. | The government publishes no canonical separator format, so any grouping would collide with citizenship/DL. |
| PAN is bare 9 digits. | No separators — they would collide with grouped citizenship numbers. |
| detectIDType is best-effort. | Prefer the specific isValid* when you know the type. |
📋 ID format reference
| ID | Format | Example |
|---|---|---|
| Citizenship | 2-4 numeric groups, first = district code [1, 77] | 12-01-78-12345 |
| PAN / VAT | 9 bare digits (no separators) | 301234567 |
| Passport (MRP) | 0 or 1 uppercase letter + 7-8 digits | M1234567, 11936491 |
| Passport (e-passport) | 2 uppercase letters + 6-8 digits | PA1234567 |
| Driving license | 2-4 numeric groups, first = district [1, 77], last ≥ 7 digits | 12-04-12345678 |
| NID | 10 bare digits (no separators) | 1234567890 |
🧰 Full API
| Function | Description |
|---|---|
| isValidCitizenship(input) | Boolean format check |
| parseCitizenship(input) | CitizenshipDetails \| null |
| formatCitizenship(details) | Canonical hyphenated string |
CitizenshipDetails: { raw, canonical, groups, districtCode?, sequence }
| Function | Description |
|---|---|
| isValidPAN(input) / isValidVAT(input) | Boolean (VAT is an alias of PAN — same 9-digit field) |
| parsePAN(input) / parseVAT(input) | PANDetails \| null |
| formatPAN(details) / formatVAT(details) | Canonical 9-digit string |
PANDetails: { raw, digits }
| Function | Description |
|---|---|
| isValidPassport(input) | Boolean (MRP or e-passport) |
| parsePassport(input) | PassportDetails \| null |
| formatPassport(details) | Canonical uppercase form |
PassportDetails: { raw, canonical, type: "MRP" \| "e-passport", prefix, sequence }
| Function | Description |
|---|---|
| isValidDrivingLicense(input) | Boolean (post-2017 smart-card format) |
| parseDrivingLicense(input) | DrivingLicenseDetails \| null |
| formatDrivingLicense(details) | Canonical hyphenated string |
DrivingLicenseDetails: { raw, canonical, groups, districtCode, sequence }
| Function | Description |
|---|---|
| isValidNID(input) | Boolean (bare 10 digits — no separators) |
| parseNID(input) | NIDDetails \| null |
| formatNID(details) | Bare 10-digit string |
NIDDetails: { raw, digits }
| Function | Description |
|---|---|
| detectIDType(input) | "passport" \| "nid" \| "pan" \| "driving-license" \| "citizenship" \| null |
🎯 Recipes
KYC form validation
import { isValidCitizenship, isValidPAN, isValidPassport } from "nepali-id-validators-pro-max";
const errors: string[] = [];
if (!isValidCitizenship(form.citizenship)) errors.push("Invalid citizenship number");
if (form.pan && !isValidPAN(form.pan)) errors.push("Invalid PAN");
if (form.passport && !isValidPassport(form.passport)) errors.push("Invalid passport number");Universal "any Nepal ID" intake
import { detectIDType } from "nepali-id-validators-pro-max";
const idType = detectIDType(userInput);
if (!idType) throw new Error("Unrecognised ID format");
console.log(`Looks like a ${idType}`);Normalise stored IDs to canonical form
import { parseCitizenship, formatCitizenship } from "nepali-id-validators-pro-max";
const cleaned = parseCitizenship(userInput);
if (cleaned) {
await db.users.update({ id, citizenship: formatCitizenship(cleaned) });
}Devanagari-digit form input
import { isValidPAN } from "nepali-id-validators-pro-max";
isValidPAN("३०१२३४५६७"); // true — Devanagari digits handled transparently🤝 Contributing
PRs welcome. Common contributions:
- Edge-case formats discovered in the wild (older citizenship layouts, regional CDO variants)
- Pre-2017 driving license format (separate
parseLegacyDrivingLicense) - Checksum logic if NIDMC / IRD ever publish one for NID or PAN
npm install
npm test
npm run typecheck
npm run build📜 License
MIT © 2026 l3lackcurtains
Made with ❤️ for the Nepali developer community.
बनाइएको नेपाली डेभलपर समुदायको लागि।
