PhoneNumbersNA 1.0.2
See the version list below for details.
dotnet add package PhoneNumbersNA --version 1.0.2
NuGet\Install-Package PhoneNumbersNA -Version 1.0.2
<PackageReference Include="PhoneNumbersNA" Version="1.0.2" />
paket add PhoneNumbersNA --version 1.0.2
#r "nuget: PhoneNumbersNA, 1.0.2"
// Install PhoneNumbersNA as a Cake Addin #addin nuget:?package=PhoneNumbersNA&version=1.0.2 // Install PhoneNumbersNA as a Cake Tool #tool nuget:?package=PhoneNumbersNA&version=1.0.2
PhoneNumbersNA
A library for parsing phone numbers. Built around the North American Numbering Plan and the NANPA formal specification.
Find this package on NuGet! 🚀
Helping you Parse Phone Numbers ☎️
The core of this library is the
var checkParse = PhoneNumber.TryParse(string input, out var phoneNumber);
function that accepts a string that you would like to parse into a single phone number. It mimics the format of int.TryParse(string input, out var value)
to make it easy to use and reason about. The PhoneNumber type that is return in the out variable contains variety of useful properties including a 10 digit string named DialedNumber which is what you would literally dial on a phone's keypad to place a call to that number. The components of the DialedNumber are also provided as integers to make them easy to work with and store. Please note, to convert the NPA, NXX, and XXXX properties to strings you'll need to use the phoneNumber.NPA.ToString("000")
method to preserve any leading zeros that aren't represented by the integer format.
For parsing a string that may contain many phone numbers use the extension method on the String class that are included in this library:
var stringlyTypedPhoneNumbers = "12060009999 15030006969 18750001111".ExtractDialedNumbers();
which will return an array of 10 digit phone numbers as strings. If you prefer the strongly typed version you can use the
var stronglyTypedPhoneNumbers = "12060009999 15030006969 18750001111".ExtractPhoneNumbers();
extension method to get an IEnumerable<PhoneNumber> result.
If you simply want a yes or no answer to whether a string is a valid NANP phone number you can use the
var checkValid = "12060991111".IsValidPhoneNumber();
to get a Boolean where a value of true means that the string is a valid phone number. There are also extension methods in a similar format for checking if a string is a valid NPA, NXX, XXXX and regular methods that are accessible by calling
var checkValid = PhoneNumbersNA.AreaCode.ValidPhoneNumber("maybeAPhoneNumber");
or accept integers like
var checkValid = PhoneNumbersNA.AreaCode.ValidPhoneNumber(int npa, int nxx, int xxxx);
A common scenario when working with 3rd party VOIP API's like the Teli API or the Call48 API is to query for blocks of available phone numbers by the NPA (Area Code) prefix for those phone numbers. To support this use case this library provides a list of every active NANP Area Code as an array on integers that is accessible by calling PhoneNumbersNA.AreaCode.All
. If you want a list of only the active non-local, non-geographic area codes you can call PhoneNumbersNA.AreaCode.NonGeographic
and similarly tollfree only Area Codes are available under PhoneNumbersNA.AreaCode.TollFree
.
Some APIs require you to provide the name of the state the area code you are looking for existing within geographically. To that end you can use the PhoneNumbers.AreaCode.AreaCodesByState
array to get a list of objects containing strings for both the short and long versions of state names and an array of all the area codes in that specific state.
Often phone number purchasing APIs make a distinction between Local phone numbers and Tollfree phone numbers. The PhoneNumber type contains a Type property that is accessible after you call the TryParse method on the string representation of a phone number. This Type property is an Enum with a value of Tollfree, NonGeographic, or Local depending on how the phone number was parsed. Using this information, you can chose the correct API endpoint to submit purchase order for that number to. If you prefer to figure out the Type of the number directly you can use the string extension methods
var checkNonGeographic = "9990221111".IsNonGeographic()
or
var checkTollFree = "9990221111".IsTollfree()
to get a Boolean as an answer.
This library is used in production by Accelerate Networks and grew organically out of a large set of utility functions that have now been condensed into PhoneNumbersNA. 🥳
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 was computed. 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 was computed. 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. |
-
net6.0
- No dependencies.
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.15 | 107 | 11/5/2024 |
1.0.14 | 817 | 4/12/2024 |
1.0.13 | 361 | 2/22/2024 |
1.0.12 | 1,922 | 5/1/2023 |
1.0.11 | 216 | 4/28/2023 |
1.0.10 | 554 | 3/9/2023 |
1.0.9 | 296 | 2/24/2023 |
1.0.8 | 846 | 7/23/2022 |
1.0.7 | 474 | 5/25/2022 |
1.0.6 | 502 | 4/3/2022 |
1.0.5 | 507 | 2/24/2022 |
1.0.4 | 458 | 2/22/2022 |
1.0.3 | 488 | 10/31/2021 |
1.0.2 | 309 | 10/19/2021 |
1.0.1 | 318 | 10/19/2021 |
1.0.0 | 338 | 10/18/2021 |