dz-id-validator
v1.0.0
Published
Zero-dependency validators for Algerian identifiers: RC, NIF, NIS, national ID (NIN), +213 phone numbers and IBAN-DZ.
Maintainers
Readme
dz-id-validator
Zero-dependency TypeScript validators for Algerian identifiers — RC, NIF, NIS, national ID (NIN),
+213phone numbers and IBAN-DZ.
🇩🇿 Built for the Algerian developer ecosystem. العربية
- Zero dependencies — tiny, tree-shakeable, browser & Node friendly.
- Dual ESM + CJS build with full TypeScript types.
- Rich results — every validator returns the reason for failure and parsed metadata (wilaya, operator, BBAN…).
Install
npm install dz-id-validatorQuick start
import {
validateIBAN,
validatePhone,
isValidNIF,
validateRC,
} from "dz-id-validator";
validateIBAN("DZ16 0079 9999 0001 2345 6789");
// { valid: true, type: "iban", normalized: "DZ1600799999000123456789",
// meta: { countryCode: "DZ", checkDigits: "16", bban: "00799999000123456789" }, errors: [] }
validatePhone("0661 23 45 67");
// { valid: true, type: "mobile", normalized: "+213661234567",
// meta: { kind: "mobile", nsn: "661234567", e164: "+213661234567", operator: "Mobilis" }, ... }
isValidNIF("160001234567890"); // true
validateRC("16/16-0123456 B");
// { valid: true, type: "rc", normalized: "16/16-0123456 B",
// meta: { year: "16", wilaya: "16", sequence: "0123456", legalForm: "B" }, ... }What it validates
| Identifier | Function | Rule |
| --------------------------------------------- | ------------------ | --------------------------------------------------------- |
| RC — Registre du Commerce | validateRC | Structural YY/WW-SSSSSSS[ L]; embedded wilaya 01–58 |
| NIF — Numéro d'Identification Fiscale | validateNIF | 15 digits |
| NIS — Numéro d'Identification Statistique | validateNIS | 15 digits |
| NIN — National ID card (biometric) | validateNIN | 18 digits |
| Mobile | validateMobile | +213 5x/6x/7x, 9-digit NSN |
| Landline | validateLandline | +213 2x/3x/4x area codes |
| Phone (either) | validatePhone | mobile or landline |
| IBAN-DZ | validateIBAN | DZ + 24 chars, ISO 7064 MOD-97-10 |
API
Result shape
Every validate* function returns a ValidationResult:
interface ValidationResult<Meta> {
valid: boolean;
type: "rc" | "nif" | "nis" | "nin" | "phone" | "mobile" | "landline" | "iban";
input: string; // original input
normalized?: string; // canonical form (when valid)
errors: { code: string; message: string }[];
meta?: Meta; // parsed details
}Boolean helpers
Prefer a quick yes/no? Use the isValid* variants:
import {
isValidRC,
isValidNIF,
isValidNIS,
isValidNIN,
isValidPhone,
isValidMobile,
isValidLandline,
isValidIBAN,
} from "dz-id-validator";
isValidMobile("+213771234567"); // truePhone helpers
import { normalizePhone, formatPhone, toNsn } from "dz-id-validator";
normalizePhone("0661234567"); // "+213661234567" (E.164)
formatPhone("0661234567"); // "0661 23 45 67" (national pretty-print)
toNsn("+213661234567"); // "661234567" (national significant number)Accepted inputs include +213…, 00213…, 0213…, a leading trunk 0, or a
bare NSN. Spaces, dots, dashes and parentheses are ignored.
IBAN helpers
import { formatIBAN, mod97 } from "dz-id-validator";
formatIBAN("DZ1600799999000123456789"); // "DZ16 0079 9999 0001 2345 6789"Wilaya helper
import { isValidWilayaCode } from "dz-id-validator";
isValidWilayaCode(16); // true (Algiers)
isValidWilayaCode(59); // false (Algeria has 58 wilayas)Notes & assumptions
- RC, NIF, NIS, NIN have no public checksum, so validation is structural (format + length + embedded wilaya range where applicable). This catches the vast majority of typos and malformed inputs.
- IBAN-DZ: Algeria is not (yet) part of the official ISO 13616 IBAN
registry. Banks issue a de-facto IBAN derived from the 20-digit RIB:
DZ+ 2 check digits + 20-digit BBAN = 24 characters, validated with the standard ISO 7064 MOD-97-10 checksum. - Mobile operator is inferred from the original number range; numbers are portable, so treat it as a hint, not a guarantee.
Development
npm install
npm run typecheck
npm test
npm run buildLicense
MIT © HassanMak29
