Tingle.Extensions.PhoneValidators
4.8.0
See the version list below for details.
dotnet add package Tingle.Extensions.PhoneValidators --version 4.8.0
NuGet\Install-Package Tingle.Extensions.PhoneValidators -Version 4.8.0
<PackageReference Include="Tingle.Extensions.PhoneValidators" Version="4.8.0" />
paket add Tingle.Extensions.PhoneValidators --version 4.8.0
#r "nuget: Tingle.Extensions.PhoneValidators, 4.8.0"
// Install Tingle.Extensions.PhoneValidators as a Cake Addin #addin nuget:?package=Tingle.Extensions.PhoneValidators&version=4.8.0 // Install Tingle.Extensions.PhoneValidators as a Cake Tool #tool nuget:?package=Tingle.Extensions.PhoneValidators&version=4.8.0
Tingle.Extensions.PhoneValidators
This library is used to validate if a phone number is valid. It can also be used to convert Kenyan phone numbers between E.164, local, and MSISDN formats.
Using attributes
The .NET framework has validation inbuilt by decorating attributes on your members. This library supports that workflow.
public class SetPhoneNumberModel
{
[Required]
public string UserId { get; set; }
[Required]
[E164Phone] // ensures value is in E.164 format
public string Primary { get; set; }
[E164Phone] // ensures all values are in E.164 format
[DataType(DataType.PhoneNumber)] // useful for generating docs in OpenAPI
public IList<string> Alternatives { get; set; }
}
Using this in AspNetCore is easy since model validation is inbuilt and enabled by default.
[Route("api/v1/[controller]")]
public class DummyController : ControllerBase
{
[HttpGet]
public Task<IActionResult> TestAsync([FromBody, Required] SetPhoneNumberModel model)
{
// If we get here, the model was already validated
// Otherwise, problem details were returned.
return Ok();
}
}
The available attributes include: |Attribute Name|Description| |--|--| |E164PhoneAttribute|Validates that the value is formatted as per the E.164 standard.| |MsisdnPhoneAttribute|Validates that the value is formatted as per the MSISDN format.| |SafaricomPhoneAttribute|Validates that the value is valid for Safaricom Kenya phone numbers| |AirtelPhoneAttribute|Validates that the value is valid for Airtel Kenya phone numbers| |TelkomPhoneAttribute|Validates that the value is valid for Telkom Kenya phone numbers|
Using Dependency Injection
First add to the services collection before they can be resolved.
Sample Usage (Safaricom validator)
[Route("api/v1/[controller]")]
public class DummyController : ControllerBase
{
private static readonly SafaricomPhoneNumberValidator phoneNumberValidator = new();
[HttpGet]
public Task<IActionResult> TestAsync([FromQuery] string phoneNumber)
{
var result = phoneNumberValidator.IsValid(phoneNumber);
if (!result) return BadRequest("Invalid Phone number!");
// Convert to MSISDN format
var msisdn = phoneNumberValidators.ToMsisdn(phoneNumber);
return Ok(msisdn);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- libphonenumber-csharp (>= 8.13.24)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net7.0
- libphonenumber-csharp (>= 8.13.24)
-
net8.0
- libphonenumber-csharp (>= 8.13.24)
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 |
---|---|---|
5.0.0 | 58 | 11/19/2024 |
4.14.1 | 239 | 10/14/2024 |
4.14.0 | 318 | 9/16/2024 |
4.13.0 | 507 | 8/13/2024 |
4.12.0 | 170 | 8/7/2024 |
4.11.2 | 273 | 7/15/2024 |
4.11.1 | 329 | 6/26/2024 |
4.11.0 | 273 | 6/6/2024 |
4.10.1 | 111 | 6/5/2024 |
4.10.0 | 182 | 5/27/2024 |
4.9.0 | 265 | 5/16/2024 |
4.8.0 | 301 | 5/5/2024 |
4.7.0 | 428 | 3/25/2024 |
4.6.0 | 349 | 3/8/2024 |
4.5.0 | 1,535 | 11/22/2023 |
4.4.1 | 230 | 11/20/2023 |
4.4.0 | 242 | 11/15/2023 |
4.3.0 | 503 | 10/18/2023 |
4.2.2 | 599 | 9/20/2023 |
4.2.1 | 834 | 8/4/2023 |
4.2.0 | 1,147 | 5/31/2023 |
4.1.1 | 281 | 5/26/2023 |
4.1.0 | 300 | 5/22/2023 |
4.0.0 | 1,175 | 3/14/2023 |
3.8.1 | 1,414 | 11/30/2022 |
3.8.0 | 513 | 11/21/2022 |
3.7.0 | 2,233 | 9/4/2022 |
3.6.0 | 1,959 | 7/4/2022 |
3.5.3 | 2,514 | 4/8/2022 |
3.5.2 | 1,924 | 1/7/2022 |
3.5.1 | 1,869 | 11/11/2021 |
3.5.0 | 489 | 11/10/2021 |
3.4.7 | 1,049 | 11/2/2021 |
3.4.6 | 616 | 10/29/2021 |
3.4.5 | 1,234 | 10/9/2021 |
3.4.4 | 1,503 | 8/9/2021 |
3.4.3 | 332 | 8/9/2021 |
3.4.2 | 1,694 | 5/26/2021 |
0.1.0-ci0015 | 217 | 5/26/2021 |