Validating phone numbers effectively with C# and the .NET frameworks
Validating user input is important to the security and proper operation of any software application. This is particularly true of data like phone numbers, which are typically private data used to deliver both application functionality, such as messaging, and security features like 2-factor authentication.
Application development frameworks, including the .NET Framework and .NET Core provide data validation capabilities to make it easier to handle standard data types more robustly. While the .NET frameworks provide for validating phone numbers, the capabilities are limited, particularly with respect to internationalization (“i18n”).
Fortunately, there is a open source library,
libphonenumber-csharp, that provides extensive resources for validating and manipulating phone numbers of all types. It’s derived from an open source library created by Google. This post shows how you can implement
libphonenumber-csharpin your .NET projects and easily leverage this powerful functionality.
.NET Data Validation
A common design pattern in software built with C ...