smart-id-validator
Version:
A package to validate official document numbers and other IDs format for various countries.
120 lines (84 loc) ⢠2.39 kB
Markdown
**Smart ID Validator** is an NPM package that helps validate various document IDs, including phone numbers, CNICs (National Identity Cards), and passports etc. The package currently supports validation for **Pakistan (PK)** and is designed to be easily extendable for other countries.
- Validate **Pakistani phone numbers** (Mobile, Landline, Toll-Free, Emergency, Shortcodes)
- Identify the **network provider** for mobile numbers
- Validate **Pakistani CNICs** (13-digit format)
- Validate **Pakistani Passports** (2-letter prefix followed by 7 digits)
- Provide **formatted output** for better readability
- Designed for **scalability**, allowing validation rules for other countries to be added
Install the package via npm:
```sh
npm install smart-id-validator
```
Or using yarn:
```sh
yarn add smart-id-validator
```
```javascript
const {
validatePhoneNumber,
validateCNIC,
validatePassport,
} = require("smart-id-validator");
```
```javascript
const result = validatePhoneNumber("03123456789", "pk");
console.log(result);
```
```json
{
"isValid": true,
"type": "mobile",
"formatted": "03123456789",
"network": "Jazz",
"country": "PK"
}
```
```javascript
const result = validateCNIC("42101-1234567-9", "pk");
console.log(result);
```
```json
{
"isValid": true,
"formatted": "42101-1234567-9",
"country": "PK"
}
```
```javascript
const result = validatePassport("AB1234567", "pk");
console.log(result);
```
```json
{
"isValid": true,
"formatted": "AB1234567",
"country": "PK"
}
```
Currently, **Pakistan (PK)** is supported. Contributions for other countries are welcome!
We welcome contributions to improve and extend this package. To contribute:
1. Fork the repository.
2. Create a new branch (`feature/new-validation`).
3. Add and test your changes.
4. Submit a pull request.
## Repository
Find the source code and contribute on GitHub:
š [GitHub Repository](https://github.com/zahidlatifdev/smart-id-validator)
## License
This package is released under the **MIT License**.
---
Feel free to contribute, report issues, or suggest improvements!