Overview
LocalRegex provides a powerfulformatNumber() extension method on String that allows you to format Zimbabwean phone numbers in different styles. This method validates the phone number and returns it in your preferred format.
The
formatNumber() method is specifically designed for Zimbabwean numbers (mobile, VOIP, and landline). It validates against Zimbabwe-specific patterns before formatting.Method Signature
Parameters
The desired output format for the phone number. See Format Types below.
Whether to strip all non-digit characters before formatting. When
true, removes spaces, parentheses, hyphens, and other formatting characters.Examples:(077) 612-3098→0776123098(024) 212-3098→0242123098
Format Types
TheFormatType enum provides three formatting options:
- Regular
- Country Code
- Country Code Plus
FormatType.regular
The standard local format with leading zero (e.g.,0777213388).This is the most common format used within Zimbabwe for mobile and landline numbers.Usage Examples
Before & After Examples
Input
Output (Regular)
Input
Output (Country Code Plus)
Exception Handling
TheformatNumber() method throws a LocalRegexException if the phone number is invalid:
Validation
The method automatically validates that the phone number matches one of these Zimbabwe patterns:- Mobile numbers: Econet, NetOne, or Telecel
- VOIP numbers: Zimbabwe VOIP providers
- Landline numbers: Zimbabwe landlines
LocalRegexException is thrown.
Related
Validation Methods
Learn about phone number validation methods
National ID Formatting
Format Zimbabwean national IDs