Overview
LocalRegex provides aformatID() extension method on String that formats Zimbabwean national identification numbers into the official format used on government-issued ID cards.
Method Signature
Parameters
The desired output format for the national ID. See Format Types below.
Format Types
TheIdFormatType enum provides two formatting options:
- Proper
- No Space
IdFormatType.proper
The official format as seen on Zimbabwean national identity cards.Format:XX-XXXXXX X XXExample: 11-223344 K 55This is the default format and matches the layout on physical ID documents issued by the Zimbabwean government.Usage Examples
Format Breakdown
The proper format11-223344 K 55 consists of:
Registration Number (6 digits)
Six digits representing the sequential registration number.Example:
223344Before & After Examples
Input
Output (Proper)
Input
Output (No Space)
Exception Handling
TheformatID() method throws a LocalRegexException if the national ID is invalid:
Case Handling
The
formatID() method automatically converts the check letter to uppercase, ensuring consistent output regardless of input casing.Validation
The method validates the national ID usingLocalRegex.isZimID() before formatting. The ID must:
- Match the Zimbabwean national ID pattern
- Contain valid district prefix
- Have the correct structure with check letter
- Include proper suffix digits
LocalRegexException is thrown with the message: "National ID is not valid".
Use Cases
User Forms
Display formatted IDs in registration and profile forms for better readability.
Database Storage
Use
IdFormatType.noSpace for consistent, space-free storage in databases.Document Generation
Format IDs in the proper government format for official documents and reports.
Data Import
Standardize ID formats when importing data from various sources.
Related
National ID Validation
Learn about national ID validation methods
Phone Number Formatting
Format Zimbabwean phone numbers