zimbabwean-id-number-validator
v1.0.4
Published
Zimbabwean national id number validator
Downloads
133
Readme
Zimbabwean ID Number Validator
The ID numbers issued in Zimbabwe consist of either 11 or 12 alphanumeric characters. Each ID contains one alphabetic letter, while the remaining characters are numeric digits. Various systems may capture ID numbers in different formats, with the most common formats including:
- 082047823Q29 (No hyphens)
- 08-2047823Q29 (Hyphen after district code)
- 08-2047823-Q-29 (Full hyphenation)
| ID | Description | | ------- | --------------------- | | 08 | District Code | | 2047823 | 6 or 7 digit sequence | | Q | Alphabetic letter | | 29 | District Code |
This package uses regular expressions to validate the input against the established patterns. It also includes a lookup of District Codes to ensure the correctness of the ID number. District Codes used in the validation procedures were acquired from the following source.
Usage
Install the package using the following command:
npm install zimbabwean-id-number-validatorUsage In ES6
import validateIdNumber from "zimbabwean-id-number-validator";
const validationResults = validateIdNumber("082047823Q21");Usage in CommonJS
const validateIdNumber = require("zimbabwean-id-number-validator");
const validationResults = validateIdNumber("082047823Q21");Advanced Usage
import { validateIdNumber } from "zimbabwean-id-number-validator";
// Validate with specific format
const result = validateIdNumber("08-2047823-Q-29", "FULL_HYPHENS");
// Available format options:
// NO_HYPHENS - 082047823Q29
// HYPHEN_AFTER_DISTRICT - 08-2047823Q29
// FULL_HYPHENS - 08-2047823-Q-29Validation Results
The validator provides detailed response objects
Successful Validation
{
isIdNumberValid: true,
description: "id number is valid"
}Format-Specific Errors
When using NO_HYPHENS
{
isIdNumberValid: false,
description: "id number must be in the format: 082047823Q29"
}When using HYPHEN_AFTER_DISTRICT
{
isIdNumberValid: false,
description: "id number must be in the format: 08-2047823Q29"
}When using FULL_HYPHENS
{
isIdNumberValid: false,
description: "id number must be in the format: 08-2047823-Q-29"
}Content Validation Errors
{
isIdNumberValid: false,
description: "id number is invalid"
}Automatic Format Detection
When no specific format is specified, the validator provides general guidance:
{
isIdNumberValid: false,
description: "id number must be in one of the formats: 082047823Q29, 08-2047823Q29, or 08-2047823-Q-29"
}