india-validator
v1.0.1
Published
A modern, comprehensive validation library for Indian formats — PAN, Aadhaar, GST, IFSC, UPI, Phone, Pincode, Vehicle, Passport and more.
Maintainers
Readme
✨ Why india-validator?
Building an Indian app? Stop copy-pasting regex from StackOverflow.
- ✅ 11 validators covering all common Indian ID/financial formats
- ✅ Parse functions — not just validate, but extract meaningful data
- ✅ Zero dependencies — pure JavaScript, works everywhere
- ✅ TypeScript support — full
.d.tstype definitions included - ✅ Verhoeff checksum for Aadhaar (real algorithm, not just regex)
- ✅ Actively maintained — unlike validate-india (last updated 2026)
- ✅ Node.js ≥ 14 and browser-compatible
📦 Installation
npm install india-validator
# or
yarn add india-validator
# or
pnpm add india-validator🚀 Quick Start
const { validatePAN, validatePhone, validateGST, parseIFSC } = require('india-validator');
validatePAN('ABCPD1234E'); // true
validatePhone('9876543210'); // true
validateGST('27AAAPZ2323M1Z6'); // true
const info = parseIFSC('HDFC0001234');
// { valid: true, bankCode: 'HDFC', bank: 'HDFC Bank', branchCode: '001234' }ESM / TypeScript:
import { validatePAN, parsePAN, validatePhone } from 'india-validator';Namespace style:
const { BharatValidator } = require('india-validator');
BharatValidator.pan.validatePAN('ABCPD1234E'); // true
BharatValidator.ifsc.parseIFSC('SBIN0001234');📖 API Reference
🪪 PAN
const { validatePAN, parsePAN } = require('india-validator');| Function | Signature | Description |
|----------|-----------|-------------|
| validatePAN | (pan: string) → boolean | Validates PAN format |
| parsePAN | (pan: string) → PANParseResult | Parses PAN into components |
parsePAN() result:
parsePAN('ABCPD1234E');
// {
// valid: true,
// pan: 'ABCPD1234E',
// entityCode: 'P',
// entityType: 'Individual',
// holderInitial: 'D'
// }Valid entity types (4th character):
| Code | Entity |
|------|--------|
| P | Individual |
| C | Company |
| H | Hindu Undivided Family |
| F | Firm / LLP |
| A | Association of Persons |
| T | Trust |
| B | Body of Individuals |
| L | Local Authority |
| J | Artificial Juridical Person |
| G | Government |
📱 Phone
const { validatePhone, normalizePhone, parsePhone } = require('india-validator');| Function | Signature | Description |
|----------|-----------|-------------|
| validatePhone | (phone: string \| number) → boolean | Validates Indian mobile number |
| normalizePhone | (phone: string \| number) → string \| null | Returns clean 10-digit number |
| parsePhone | (phone: string \| number) → PhoneParseResult | Parses phone details |
validatePhone('+919876543210'); // true
validatePhone('9876543210'); // true
validatePhone('98765 43210'); // true (spaces allowed)
normalizePhone('+919876543210'); // '9876543210'
parsePhone('9876543210');
// {
// valid: true,
// normalized: '9876543210',
// formatted: '+91 98765 43210',
// series: 'Airtel / Jio / Vodafone / Others'
// }🔢 Aadhaar
const { validateAadhaar, maskAadhaar, formatAadhaar } = require('india-validator');| Function | Signature | Description |
|----------|-----------|-------------|
| validateAadhaar | (aadhaar, options?) → boolean | Validates with Verhoeff checksum |
| maskAadhaar | (aadhaar) → string \| null | Returns XXXX XXXX 1234 |
| formatAadhaar | (aadhaar) → string \| null | Returns 1234 5678 9012 |
validateAadhaar('2345 6789 0123'); // true (with checksum)
validateAadhaar('234567890123', { skipChecksum: true }); // skip Verhoeff check
maskAadhaar('234567890123'); // 'XXXX XXXX 0123'
formatAadhaar('234567890123'); // '2345 6789 0123'Note: Aadhaar validation uses the Verhoeff algorithm for checksum verification — the same algorithm used by UIDAI.
🧾 GST
const { validateGST, parseGST } = require('india-validator');validateGST('27AAAPZ2323M1Z6'); // true
parseGST('27AAAPZ2323M1Z6');
// {
// valid: true,
// gstin: '27AAAPZ2323M1Z6',
// stateCode: '27',
// state: 'Maharashtra',
// pan: 'AAAPZ2323M',
// entityNumber: '1',
// checksum: '6'
// }🏦 IFSC
const { validateIFSC, parseIFSC } = require('india-validator');validateIFSC('SBIN0001234'); // true
parseIFSC('HDFC0001234');
// {
// valid: true,
// ifsc: 'HDFC0001234',
// bankCode: 'HDFC',
// bank: 'HDFC Bank',
// branchCode: '001234'
// }Recognizes 35+ major banks including SBI, HDFC, ICICI, Axis, Kotak, PNB, and all Payment Banks.
📮 Pincode
const { validatePincode, parsePincode } = require('india-validator');validatePincode('400001'); // true (Mumbai)
validatePincode(400001); // true (numeric input works)
parsePincode('400001');
// {
// valid: true,
// pincode: '400001',
// circle: 4,
// region: 'Maharashtra, Goa, Madhya Pradesh, Chhattisgarh',
// subCircle: 0,
// sortingDistrict: 0,
// postOfficeCode: '001'
// }💸 UPI
const { validateUPI, parseUPI } = require('india-validator');validateUPI('user@okicici'); // true
validateUPI('9876543210@paytm'); // true
validateUPI('name@ybl'); // true (PhonePe)
parseUPI('username@oksbi');
// {
// valid: true,
// vpa: 'username@oksbi',
// username: 'username',
// handle: 'oksbi',
// bank: 'State Bank of India'
// }Recognizes 55+ UPI handles including all major bank handles, PhonePe, Google Pay, Paytm, WhatsApp Pay, and more.
🚗 Vehicle Registration
const { validateVehicle, parseVehicle } = require('india-validator');validateVehicle('MH12AB1234'); // true
validateVehicle('MH 12 AB 1234'); // true (spaces OK)
validateVehicle('22BH1234AA'); // true (BH series)
parseVehicle('MH12AB1234');
// {
// valid: true,
// type: 'Standard',
// registration: 'MH12AB1234',
// stateCode: 'MH',
// state: 'Maharashtra'
// }
parseVehicle('22BH1234AA');
// { valid: true, type: 'BH Series (Bharat)', year: '22', ... }🛂 Passport
const { validatePassport, parsePassport } = require('india-validator');validatePassport('P1234567'); // true
validatePassport('D1234567'); // true (diplomatic)
parsePassport('P1234567');
// {
// valid: true,
// passport: 'P1234567',
// typeCode: 'P',
// type: 'Regular / Ordinary',
// serial: '1234567'
// }🗳️ Voter ID (EPIC)
const { validateVoterID, parseVoterID } = require('india-validator');validateVoterID('ABC1234567'); // true
parseVoterID('ABC1234567');
// { valid: true, voterId: 'ABC1234567', areaCode: 'ABC', serial: '1234567' }🚦 Driving License
const { validateDrivingLicense, parseDrivingLicense } = require('india-validator');validateDrivingLicense('MH0120110123456'); // true
validateDrivingLicense('MH-01-2011-0123456'); // true (with dashes)
parseDrivingLicense('MH0120110123456');
// {
// valid: true,
// stateCode: 'MH',
// state: 'Maharashtra',
// rtoCode: '01',
// year: '2011',
// serial: '0123456'
// }🧪 Testing
npm test # run all tests
npm run test:watch # watch mode
npm test -- --coverage # with coverage report🤝 Contributing
Contributions are welcome! Please check CONTRIBUTING.md for guidelines.
Want to add a validator? Open an issue or PR. Planned additions:
- [ ] TAN (Tax Deduction Account Number)
- [ ] CIN (Company Identification Number)
- [ ] DIN (Director Identification Number)
- [ ] Bank account number (format validation)
- [ ] MMID (Mobile Money Identifier)
📄 License
MIT © 2026 Harsh Dobariya
