SAValidation.PhoneNumbers
1.0.4
dotnet add package SAValidation.PhoneNumbers --version 1.0.4
NuGet\Install-Package SAValidation.PhoneNumbers -Version 1.0.4
<PackageReference Include="SAValidation.PhoneNumbers" Version="1.0.4" />
<PackageVersion Include="SAValidation.PhoneNumbers" Version="1.0.4" />
<PackageReference Include="SAValidation.PhoneNumbers" />
paket add SAValidation.PhoneNumbers --version 1.0.4
#r "nuget: SAValidation.PhoneNumbers, 1.0.4"
#:package SAValidation.PhoneNumbers@1.0.4
#addin nuget:?package=SAValidation.PhoneNumbers&version=1.0.4
#tool nuget:?package=SAValidation.PhoneNumbers&version=1.0.4
SAValidation.PhoneNumbers
South African phone number validation library.
NuGet: https://www.nuget.org/packages/SAValidation.PhoneNumbers/ GitHub: https://github.com/NuGetPackagesPGLN/SAValidation
Installation
dotnet add package SAValidation.PhoneNumbers
Features
Mobile Numbers
- Vodacom (082, 072)
- MTN (083, 076)
- Cell C (084, 079)
- Telkom Mobile (081)
- Neotel (085)
Landline Numbers with Area Detection
- Johannesburg (011)
- Pretoria (012)
- Cape Town (021)
- Durban (031)
- Port Elizabeth (041)
- Bloemfontein (051)
- And 30+ other areas
Special Numbers
- Toll-Free: 0800 numbers
- Premium Rate: 0860, 0861 numbers
- Emergency: 10111, 112, 107, 10177, 1022
Format Handling
- Local format: 0825551234
- International format: +27825551234
- With spaces: 082 555 1234
- With dashes: 082-555-1234
- With parentheses: (082) 555-1234
Quick Usage
using SAValidation.PhoneNumbers;
// Simple validation bool isValid = "0825551234".IsValidSouthAfricanPhoneNumber();
// Detailed validation var result = "0825551234".ValidateSouthAfricanPhoneNumber();
if (result.IsValid) { Console.WriteLine($"Type: {result.NumberType}"); // Mobile Console.WriteLine($"Operator: {result.Operator}"); // Vodacom Console.WriteLine($"Normalized: {result.NormalizedNumber}"); // +27825551234 }
Detailed Examples
Mobile Number Detection
// Vodacom var vodacom = "0825551234".ValidateSouthAfricanPhoneNumber(); Console.WriteLine(vodacom.Operator); // Vodacom
// MTN var mtn = "0835551234".ValidateSouthAfricanPhoneNumber(); Console.WriteLine(mtn.Operator); // MTN
// Cell C var cellc = "0845551234".ValidateSouthAfricanPhoneNumber(); Console.WriteLine(cellc.Operator); // CellC
Landline Area Detection
var jhb = "0115551234".ValidateSouthAfricanPhoneNumber(); Console.WriteLine(jhb.AreaDescription); // Johannesburg & Gauteng
var cpt = "0215551234".ValidateSouthAfricanPhoneNumber(); Console.WriteLine(cpt.AreaDescription); // Cape Town & Winelands
var durban = "0315551234".ValidateSouthAfricanPhoneNumber(); Console.WriteLine(durban.AreaDescription); // Durban & eThekwini
Different Input Formats
// All these return the same normalized result: +27825551234 var formats = new[] { "0825551234", "082 555 1234", "082-555-1234", "+27 82 555 1234", "27825551234" };
foreach (var format in formats) { var result = format.ValidateSouthAfricanPhoneNumber(); Console.WriteLine($"{format} → {result.NormalizedNumber}"); }
Special Numbers
// Toll-Free var tollFree = "0800123456".ValidateSouthAfricanPhoneNumber(); Console.WriteLine(tollFree.NumberType); // TollFree
// Premium var premium = "08615551234".ValidateSouthAfricanPhoneNumber(); Console.WriteLine(premium.NumberType); // Premium
// Emergency var emergency = "10111".ValidateSouthAfricanPhoneNumber(); Console.WriteLine(emergency.NumberType); // Emergency
API Reference
PhoneNumberValidator Class
| Method | Description |
|---|---|
| Validate(string phoneNumber) | Returns detailed validation result |
| IsValid(string phoneNumber) | Quick true/false validation |
Extension Methods
| Method | Description |
|---|---|
| IsValidSouthAfricanPhoneNumber(this string) | Quick validation |
| ValidateSouthAfricanPhoneNumber(this string) | Detailed validation |
PhoneNumberValidationResult Properties
| Property | Description | Example |
|---|---|---|
| IsValid | Whether the number is valid | true / false |
| NumberType | Type of number | Mobile, Landline, TollFree, Premium, Emergency |
| Operator | Mobile network operator | Vodacom, MTN, CellC, Telkom, Neotel |
| AreaCode | Geographic area code | 011, 021, 031 |
| AreaDescription | Description of the area | "Johannesburg & Gauteng" |
| NormalizedNumber | International format | +27825551234 |
| CleanedNumber | Digits only | 0825551234 |
| OriginalNumber | Original input | As provided |
| ErrorMessage | Error details if invalid | "Invalid length" |
Error Handling
var invalid = "123".ValidateSouthAfricanPhoneNumber(); if (!invalid.IsValid) { Console.WriteLine(invalid.ErrorMessage); // "Invalid length: SA numbers should be 9-11 digits (got 3)" }
Contributing
Contributions are welcome! Please submit pull requests to the GitHub repository.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- SAValidation.Common (>= 1.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.4 | 90 | 3/12/2026 |