Skip to main content
This guide will walk you through the most common use cases for LocalRegex. You’ll learn how to validate mobile numbers, national IDs, emails, and format phone numbers.

Prerequisites

Make sure you have installed LocalRegex in your project before continuing.
1

Import LocalRegex

First, import the LocalRegex package in your Dart file:
import 'package:localregex/localregex.dart';
2

Validate mobile numbers

LocalRegex provides multiple methods for validating Zimbabwean mobile numbers:
// Validate any Zimbabwean mobile number (Econet, NetOne, or Telecel)
final isValidMobile = LocalRegex.isZimMobile('0777123456');
print(isValidMobile); // true

// Validate specific network providers
final isEconet = LocalRegex.isEconet('0777123456');
print(isEconet); // true

final isNetone = LocalRegex.isNetone('0712345678');
print(isNetone); // true

final isTelecel = LocalRegex.isTelecel('0733456789');
print(isTelecel); // true
Use LocalRegex.isZimMobile() when you need to validate any Zimbabwean mobile number regardless of the provider. For international numbers, use LocalRegex.isValidMobile().
3

Validate national IDs and other documents

Validate various Zimbabwe-specific identification documents:
// Validate national ID
final isValidID = LocalRegex.isZimID('63-123456A78');
print(isValidID); // true

// Validate passport number
final isValidPassport = LocalRegex.isZimPassport('AN123456');
print(isValidPassport); // true

// Validate driver's license
final isValidLicense = LocalRegex.isZimDriversLicence('12345AB');
print(isValidLicense); // true

// Validate vehicle number plate
final isValidPlate = LocalRegex.isZimNumberPlate('ABC-1234');
print(isValidPlate); // true
4

Validate emails and other common patterns

LocalRegex also supports validation for common patterns like emails, URLs, and passwords:
// Validate email address
final isValidEmail = LocalRegex.isEmail('[email protected]');
print(isValidEmail); // true

// Validate URL
final isValidUrl = LocalRegex.isUrl('https://www.example.com');
print(isValidUrl); // true

// Validate password (min 8 chars, 1 uppercase, 1 number, 1 special char)
final isValidPassword = LocalRegex.isPassword('MyP@ssw0rd');
print(isValidPassword); // true
5

Format phone numbers

Convert phone numbers between different formats using the formatNumber() extension method:
// Format to regular format (0777123456)
final regular = '263777123456'.formatNumber(
  formatType: FormatType.regular,
);
print(regular); // 0777123456

// Format to country code (263777123456)
final countryCode = '0777123456'.formatNumber(
  formatType: FormatType.countryCode,
);
print(countryCode); // 263777123456

// Format to country code with plus (+263777123456)
final countryCodePlus = '0777123456'.formatNumber(
  formatType: FormatType.countryCodePlus,
);
print(countryCodePlus); // +263777123456
The formatNumber() method automatically handles phone numbers with spaces, dashes, or parentheses by cleaning them before formatting.
6

Format national IDs

Format national IDs to match the official document format:
// Format national ID to proper format (11-223344 K 55)
final formattedID = '11223344K55'.formatID(
  formatType: IdFormatType.proper,
);
print(formattedID); // 11-223344 K 55

// Format without spaces
final noSpaces = '11-223344 K 55'.formatID(
  formatType: IdFormatType.noSpace,
);
print(noSpaces); // 11223344K55

Complete example

Here’s a complete example that demonstrates multiple validation and formatting features:
import 'package:localregex/localregex.dart';

void main() {
  // Validate different types of data
  print('Mobile validation:');
  print(LocalRegex.isZimMobile('0777123456')); // true
  print(LocalRegex.isEconet('0777123456')); // true
  
  print('\nDocument validation:');
  print(LocalRegex.isZimID('63-123456A78')); // true
  print(LocalRegex.isZimPassport('AN123456')); // true
  
  print('\nCommon pattern validation:');
  print(LocalRegex.isEmail('[email protected]')); // true
  print(LocalRegex.isUrl('https://example.com')); // true
  
  print('\nPhone number formatting:');
  final phoneNumber = '0777123456';
  print(phoneNumber.formatNumber(
    formatType: FormatType.regular,
  )); // 0777123456
  print(phoneNumber.formatNumber(
    formatType: FormatType.countryCode,
  )); // 263777123456
  print(phoneNumber.formatNumber(
    formatType: FormatType.countryCodePlus,
  )); // +263777123456
  
  print('\nNational ID formatting:');
  final nationalID = '11223344K55';
  print(nationalID.formatID(
    formatType: IdFormatType.proper,
  )); // 11-223344 K 55
}

Next steps

Now that you understand the basics, explore more advanced features:

Mobile number validation

Learn about all mobile number validation methods

Document validation

Validate IDs, passports, licenses, and number plates

Phone number formatting

Advanced phone number formatting options

VoIP validation

Validate VoIP numbers from various providers

Build docs developers (and LLMs) love