SAValidation.Common 1.0.4

dotnet add package SAValidation.Common --version 1.0.4
                    
NuGet\Install-Package SAValidation.Common -Version 1.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SAValidation.Common" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SAValidation.Common" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="SAValidation.Common" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SAValidation.Common --version 1.0.4
                    
#r "nuget: SAValidation.Common, 1.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SAValidation.Common@1.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SAValidation.Common&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=SAValidation.Common&version=1.0.4
                    
Install as a Cake Tool

SAValidation.Common

Shared utilities for South African validation libraries.

NuGet: https://www.nuget.org/packages/SAValidation.Common/ GitHub: https://github.com/NuGetPackagesPGLN/SAValidation

Installation

dotnet add package SAValidation.Common

Features

  • String Extensions: Clean numbers, extract digits, safe substring operations
  • Guard Clauses: Defensive programming helpers
  • Shared Utilities: Common functionality used by all SAValidation packages
  • Regex Helpers: Pre-compiled regex for optimal performance
  • Null Safety: Built with nullable reference types

Usage Examples

Clean a phone number (remove spaces, dashes, parentheses)

using SAValidation.Common;

string dirty = "082 555 1234"; string clean = dirty.CleanNumber(); // Result: "0825551234"

string withDashes = "082-555-1234"; string clean2 = withDashes.CleanNumber(); // Result: "0825551234"

string withParentheses = "(082) 555-1234"; string clean3 = withParentheses.CleanNumber(); // Result: "0825551234"

Extract only digits from any string

string mixed = "+27 (82) 555-1234"; string digits = mixed.ExtractDigits(); // Result: "27825551234"

string letters = "ABC123DEF456"; string digits2 = letters.ExtractDigits(); // Result: "123456"

Check if string contains only digits

string numbers = "123456"; bool isDigits = numbers.IsAllDigits(); // true

string mixed = "123abc"; bool isDigits2 = mixed.IsAllDigits(); // false

Check if string starts with any prefix

string phone = "0825551234"; bool startsWithMobile = phone.StartsWithAny("082", "083", "084"); // Result: true (starts with 082)

string landline = "0115551234"; bool startsWithMobile2 = landline.StartsWithAny("082", "083", "084"); // Result: false

Safe substring with bounds checking

string text = "0825551234";

// Normal usage string sub1 = text.SafeSubstring(0, 3); // "082"

// Bounds checking - won't throw exception string sub2 = text.SafeSubstring(8, 10); // "34" (only takes available characters)

string empty = null; string sub3 = empty.SafeSubstring(0, 5); // "" (handles null safely)

API Reference

StringExtensions Methods

Method Description Example
CleanNumber() Removes spaces, dashes, parentheses, dots "082 555 1234" → "0825551234"
ExtractDigits() Returns only digits from string "+27 (82) 555-1234" → "27825551234"
IsAllDigits() Checks if string contains only digits "123456" → true
StartsWithAny() Checks if string starts with any of the provided prefixes "0825551234" with ["082","083"] → true
SafeSubstring() Gets substring with bounds checking "0825551234", 8, 10 → "34"

Guard Class Methods

Method Description
AgainstNullOrWhiteSpace() Throws if string is null or whitespace
AgainstOutOfRange() Throws if value is outside specified range

Contributing

Contributions are welcome! Please submit pull requests to the GitHub repository.

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

License

MIT

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SAValidation.Common:

Package Downloads
SAValidation.PhoneNumbers

South African phone number validation library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 100 3/12/2026