iran-national-code-validator
v0.0.1
Published
Validate Iranian national ID (کد ملی ایران) — Simple & precise validator.
Maintainers
Readme
🇮🇷 Iranian National Code Validator
A simple and lightweight TypeScript utility to validate Iranian national ID codes (کد ملی).
This package checks if a given 10-digit Iranian national code is valid based on checksum validation rules.
📦 Installation
npm install iran-national-code-validatoror
yarn add iran-national-code-validatoror
pnpm add iran-national-code-validator🧠 Usage
import validateIranianNationalCode from "iran-national-code-validator";
console.log(validateIranianNationalCode("0084575948")); // ✅ true
console.log(validateIranianNationalCode("1234567891")); // ❌ false
console.log(validateIranianNationalCode("0000000000")); // ❌ false⚙️ Project Structure
├── src/
│ ├── index.ts # Main validation function
├── package.json
├── tsconfig.json
└── README.md📜 Algorithm Explanation
The Iranian national code consists of 10 digits. The last digit is a checksum calculated from the first 9 digits using this formula:
- Multiply each of the first 9 digits by a descending weight (from 10 down to 2).
- Sum all results.
- Compute the remainder of the sum divided by 11.
- If the remainder is less than 2, it must equal the checksum digit.
- If the remainder is 2 or more, the checksum digit must equal
11 - remainder.
Example:
Code: 0084575948
Weights: 10 9 8 7 6 5 4 3 2
Result: valid ✅🧰 Development
To run in development mode:
npm install🧑💻 Author
Ali Mortazavi JavaScript / TypeScript Developer GitHub
🪪 License
MIT License © 2025 Ali Mortazavi
