Boost Your .NET Projects with Spargine: Global Phone Number and Postal Code Validation Made Easy

Spargine is a collection of open-source assemblies and NuGet packages designed for .NET 10, which I have been developing and maintaining since the release of .NET Framework 2. These assemblies are not only a core part of my projects but are also actively deployed in production environments across several companies I collaborate with.

Get Spargine

You can access the source code and NuGet packages here:

Validating phone numbers and postal codes across different countries is one of those problems that sounds simple… until you try to implement it. Every country has its own formats, lengths, prefixes, and validation rules. Hardcoding them is error-prone, maintaining them is painful, and rolling your own solution is almost guaranteed to miss edge cases.

That’s exactly why I created CountryPhonePostalInfoRepository in the DotNetTips.Spargine.Core assembly and NuGet package.

This repository gives you a centralized, reliable, and high-performance way to validate phone numbers and postal codes for countries around the world using standardized ISO codes and built-in rules. Instead of hunting down regex patterns and country-specific formats, you get a clean API that just works. Simple. Fast. Accurate.

Whether you’re building global applications, validating user input, or enforcing data integrity in enterprise systems, this type eliminates guesswork and dramatically reduces validation complexity.

Methods

  • GetCountryPhonePostalInfo()
    Retrieves a read-only collection containing all country phone and postal information records.
    Returns a collection of CountryPhonePostalInfo with the following properties:
    Id, Iso2, Iso3, Name, PhoneCode, PhoneNumberLength, PostalFormat, PostalRegex
  • GetCountryPhonePostalInfo(string countryNameOrIso)
    Retrieves country phone and postal information by country name or ISO code.
  • ValidatePhoneNumber(string countryNameOrIso, string phoneNumber, bool validateCountryCode)
    Validates a phone number for a given country using its name or ISO code.
    Optionally validates the country code portion of the number.
  • ValidatePostalCode(string countryNameOrIso, string postalCode)
    Validates a postal code for a given country using its name or ISO code.
    Returns an enum with values: Invalid, Unknown, or Valid.

Examples

Validating a phone number:

var result = CountryPhonePostalInfoRepository.ValidatePhoneNumber(countryNameOrIso: "Dominican Republic", phoneNumber: "1-809-555-666-7777", validateCountryCode: true);

Validating postal code:

var result = CountryPhonePostalInfoRepository.ValidatePostalCode(countryNameOrIso: "United States", postalCode: "92130-1234");

Summary

Global validation doesn’t have to be complicated, fragile, or slow.
CountryPhonePostalInfoRepository gives you a rock-solid foundation for validating phone numbers and postal codes across countries with confidence and precision.

Instead of maintaining your own patterns, formats, and rules, you get:

  • Consistent validation logic
  • Country-aware accuracy
  • Clean, readable APIs
  • Reduced technical debt
  • Faster development

The next time your application needs reliable international input validation, plug in CountryPhonePostalInfoRepository from Spargine and let your code validate like a world tour rock star—tight, precise, and absolutely in tune.

I created the metadata for this repository by aggregating information from authoritative online sources. If you encounter any issues validating phone numbers or postal codes, please let me know—I’m happy to review and correct them promptly.

Get Involved!

The success of open-source projects like Spargine relies on community contributions. If you find these updates useful or have ideas for further improvements, I encourage you to contribute by:

  • Submitting pull requests
  • Reporting issues
  • Suggesting new features

Your input is invaluable in making Spargine an even more powerful tool for the .NET community.

If you are interested in contributing or have any questions, feel free to contact me via email at dotnetdave@live.com. Your support and collaboration are greatly appreciated!

Thank you, and happy coding!

Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$100.00
$5.00
$15.00
$100.00
$5.00
$15.00
$100.00

Or enter a custom amount

$

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

If you liked this article, please buy David a cup of Coffee by going here: https://www.buymeacoffee.com/dotnetdave

© The information in this article is copywritten and cannot be preproduced in any way without express permission from David McCarter.


Discover more from dotNetTips.com

Subscribe to get the latest posts sent to your email.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.