libphonenumber-csharp
8.13.52
Prefix Reserved
dotnet add package libphonenumber-csharp --version 8.13.52
NuGet\Install-Package libphonenumber-csharp -Version 8.13.52
<PackageReference Include="libphonenumber-csharp" Version="8.13.52" />
paket add libphonenumber-csharp --version 8.13.52
#r "nuget: libphonenumber-csharp, 8.13.52"
// Install libphonenumber-csharp as a Cake Addin #addin nuget:?package=libphonenumber-csharp&version=8.13.52 // Install libphonenumber-csharp as a Cake Tool #tool nuget:?package=libphonenumber-csharp&version=8.13.52
C# port of Google's libphonenumber library.
The code was rewritten from the Java source mostly unchanged, please refer to the original documentation for sample code and API documentation.
The original Apache License 2.0 was preserved.
See this for details about the port.
Phone number metadata is updated in the Google repo approximately every two weeks. This library is automatically updated by a scheduled github action to include the latest metadata, usually within a day.
Installation
Run the following command to add this library to your project
dotnet add package libphonenumber-csharp
Available on NuGet as package libphonenumber-csharp
.
Examples
Parsing a phone number
using PhoneNumbers;
var phoneNumberUtil = PhoneNumberUtil.GetInstance();
var e164PhoneNumber = "+44 117 496 0123";
var nationalPhoneNumber = "2024561111";
var smsShortNumber = "83835";
var phoneNumber = phoneNumberUtil.Parse(e164PhoneNumber, null);
phoneNumber = phoneNumberUtil.Parse(nationalPhoneNumber, "US");
phoneNumber = phoneNumberUtil.Parse(smsShortNumber, "US");
Formatting a phone number
using PhoneNumbers;
var phoneNumberUtil = PhoneNumberUtil.GetInstance();
var phoneNumber = phoneNumberUtil.Parse("+14156667777", "US");
var formattedPhoneNumber = phoneNumberUtil.Format(phoneNumber, PhoneNumberFormat.INTERNATIONAL);
var formattedPhoneNumberNational = phoneNumberUtil.Format(phoneNumber, PhoneNumberFormat.NATIONAL);
Console.WriteLine(formattedPhoneNumber.ToString()); // +1 415-666-7777
Console.WriteLine(formattedPhoneNumberNational.ToString()); // (415) 666-7777
Check if a phone number is valid
using PhoneNumbers;
var phoneNumberUtil = PhoneNumberUtil.GetInstance();
var phoneNumber = phoneNumberUtil.Parse("+14156667777", "US");
var isValid = phoneNumberUtil.IsValidNumber(phoneNumber);
Console.WriteLine(isValid); // true
Get the type of a phone number
using PhoneNumbers;
var phoneNumberUtil = PhoneNumberUtil.GetInstance();
var phoneNumber = phoneNumberUtil.Parse("+14156667777", "US");
var numberType = phoneNumberUtil.GetNumberType(phoneNumber);
Console.WriteLine(numberType); // PhoneNumberType.FIXED_LINE_OR_MOBILE
See PhoneNumberType.cs for the various possible types of phone numbers
Get the region code for a phone number
using PhoneNumbers;
var phoneNumberUtil = PhoneNumberUtil.GetInstance();
var phoneNumber = phoneNumberUtil.Parse("+14156667777", null);
var regionCode = phoneNumberUtil.GetRegionCodeForNumber(phoneNumber);
Console.WriteLine(regionCode); // US
Features
- Parsing/formatting/validating phone numbers for all countries/regions of the world.
- GetNumberType - gets the type of the number based on the number itself; able to distinguish Fixed-line, Mobile, Toll-free, Premium Rate, Shared Cost, VoIP and Personal Numbers (whenever feasible).
- IsNumberMatch - gets a confidence level on whether two numbers could be the same.
- GetExampleNumber/GetExampleNumberByType - provides valid example numbers for 218 countries/regions, with the option of specifying which type of example phone number is needed.
- IsPossibleNumber - quickly guessing whether a number is a possible phone number by using only the length information, much faster than a full validation.
- AsYouTypeFormatter - formats phone numbers on-the-fly when users enter each digit.
- FindNumbers - finds numbers in text input
See PhoneNumberUtil.cs for the various methods and properties available.
ToDo
- port read / write source xml data to binary for better performance and smaller .nupkg size (WIP)
- update / add / port new unit tests and logging from java source
How to unfold automatic generated files
- Install Jetbrains - Resharper for Visual Studio
- File by file, right click and "Cleanup code"
- Check the unfolded file
Running tests locally
To run tests locally, you will need a zip version of the geocoding.zip
file stored in the resources
folder
and testgeocoding.zip
file stored in the resources/test
folder.
On linux, you can run the following commands to generate the zip accordingly
(cd resources/geocoding; zip -r ../../resources/geocoding.zip *)
(cd resources/test/geocoding; zip -r ../../../resources/test/testgeocoding.zip *)
For windows, you can use the following powershell script
Compress-Archive -Path "resources\geocoding\*" -DestinationPath "resources\geocoding.zip"
Compress-Archive -Path "resources\test\geocoding\*" -DestinationPath "resources\test\testgeocoding.zip"
Contributing
See CONTRIBUTING.md
Donations
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 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 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 is compatible. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- System.Collections.Immutable (>= 1.7.1)
- System.IO.Compression (>= 4.3.0)
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (118)
Showing the top 5 NuGet packages that depend on libphonenumber-csharp:
Package | Downloads |
---|---|
N3O.Umbraco.Validation
TODO |
|
OrchardCore.Users
Orchard Core CMS is a Web Content Management System (CMS) built on top of the Orchard Core Framework. The Users module adds user management functionality. |
|
OrchardCore.Application.Cms.Core.Targets
Orchard Core CMS is a Web Content Management System (CMS) built on top of the Orchard Core Framework. Converts the application into a modular OrchardCore CMS application with TheAdmin theme but without any front-end Themes. |
|
TheTheme
Orchard Core CMS is a Web Content Management System (CMS) built on top of the Orchard Core Framework. The default Theme - Can be used as base theme for new themes. |
|
OrchardCore.Application.Cms.Targets
Orchard Core CMS is a Web Content Management System (CMS) built on top of the Orchard Core Framework. Converts the application into a modular OrchardCore CMS application with following themes. - TheAdmin Theme - SafeMode Theme - TheAgency Theme - TheBlog Theme - TheComingSoon Theme - TheTheme theme |
GitHub repositories (5)
Showing the top 5 popular GitHub repositories that depend on libphonenumber-csharp:
Repository | Stars |
---|---|
OrchardCMS/OrchardCore
Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
|
|
ONLYOFFICE/CommunityServer
Free open source office suite with business productivity tools: document and project management, CRM, mail aggregator.
|
|
bitfoundation/bitplatform
Build all of your apps using what you already know and love ❤️
|
|
notifo-io/notifo
Multi channel notification service for collaboration tools, e-commerce, news service and more.
|
|
shr670377723/CommunityServer-master
|
Version | Downloads | Last updated |
---|---|---|
8.13.52 | 36,742 | 12/13/2024 |
8.13.51 | 82,507 | 12/2/2024 |
8.13.50 | 142,166 | 11/16/2024 |
8.13.49 | 155,287 | 11/4/2024 |
8.13.48 | 95,448 | 10/23/2024 |
8.13.47 | 360,004 | 10/4/2024 |
8.13.46 | 141,749 | 9/25/2024 |
8.13.45 | 325,858 | 9/6/2024 |
8.13.44 | 204,451 | 8/26/2024 |
8.13.43 | 324,477 | 8/9/2024 |
8.13.42 | 203,583 | 7/26/2024 |
8.13.41 | 22,366 | 7/25/2024 |
8.13.40 | 454,304 | 7/3/2024 |
8.13.39 | 328,688 | 6/15/2024 |
8.13.38 | 180,431 | 6/5/2024 |
8.13.37 | 662,136 | 5/17/2024 |
8.13.36 | 227,130 | 5/3/2024 |
8.13.35 | 334,439 | 4/19/2024 |
8.13.34 | 343,577 | 4/5/2024 |
8.13.33 | 311,688 | 3/25/2024 |
8.13.32 | 302,953 | 3/12/2024 |
8.13.31 | 243,249 | 2/25/2024 |
8.13.30 | 367,917 | 2/9/2024 |
8.13.29 | 358,431 | 1/26/2024 |
8.13.28 | 21,480 | 1/25/2024 |
8.13.27 | 709,198 | 12/21/2023 |
8.13.26 | 525,881 | 11/29/2023 |
8.13.25 | 343,089 | 11/20/2023 |
8.13.24 | 618,097 | 10/31/2023 |
8.13.23 | 367,500 | 10/17/2023 |
8.13.22 | 414,934 | 9/29/2023 |
8.13.21 | 209,294 | 9/20/2023 |
8.13.20 | 331,169 | 9/7/2023 |
8.13.19 | 320,025 | 8/22/2023 |
8.13.18 | 403,975 | 8/3/2023 |
8.13.17 | 140,781 | 7/27/2023 |
8.13.16 | 231,328 | 7/11/2023 |
8.13.15 | 1,692 | 7/11/2023 |
8.13.14 | 698,308 | 6/15/2023 |
8.13.13 | 1,717 | 6/15/2023 |
8.13.12 | 1,727 | 6/15/2023 |
8.13.11 | 1,130,985 | 4/27/2023 |
8.13.10 | 121,834 | 4/20/2023 |
8.13.9 | 214,523 | 4/10/2023 |
8.13.8 | 193,612 | 3/27/2023 |
8.13.7 | 767,715 | 3/3/2023 |
8.13.6 | 558,201 | 2/10/2023 |
8.13.5 | 250,145 | 1/29/2023 |
8.13.4 | 394,823 | 1/9/2023 |
8.13.3 | 441,250 | 12/22/2022 |
8.13.2 | 691,840 | 12/8/2022 |
8.13.1 | 257,085 | 11/28/2022 |
8.13.0 | 548,135 | 11/8/2022 |
8.12.57 | 808,526 | 10/14/2022 |
8.12.56 | 819,863 | 9/23/2022 |
8.12.55 | 515,310 | 9/9/2022 |
8.12.54 | 435,301 | 8/22/2022 |
8.12.53 | 487,309 | 8/8/2022 |
8.12.52 | 494,618 | 7/19/2022 |
8.12.51.1 | 155,559 | 7/12/2022 |
8.12.50 | 835,915 | 6/13/2022 |
8.12.49 | 392,414 | 6/1/2022 |
8.12.48 | 314,530 | 5/18/2022 |
8.12.47 | 6,523 | 5/18/2022 |
8.12.46 | 825,457 | 4/15/2022 |
8.12.45 | 1,144,542 | 3/14/2022 |
8.12.44 | 104,577 | 3/9/2022 |
8.12.43 | 507,502 | 2/14/2022 |
8.12.42 | 1,986 | 2/14/2022 |
8.12.41 | 1,991 | 2/14/2022 |
8.12.40 | 2,082 | 2/14/2022 |
8.12.39 | 2,057 | 2/14/2022 |
8.12.38 | 1,748,814 | 12/15/2021 |
8.12.37 | 2,524 | 12/15/2021 |
8.12.36 | 2,385 | 12/15/2021 |
8.12.35 | 2,175 | 12/15/2021 |
8.12.34 | 1,844,214 | 10/7/2021 |
8.12.33 | 420,916 | 9/23/2021 |
8.12.32 | 227,548 | 9/11/2021 |
8.12.31 | 2,539 | 9/11/2021 |
8.12.30 | 302,797 | 8/18/2021 |
8.12.29 | 2,330 | 8/18/2021 |
8.12.28 | 478,701 | 7/23/2021 |
8.12.27 | 263,149 | 7/8/2021 |
8.12.26 | 151,713 | 6/25/2021 |
8.12.25 | 139,183 | 6/16/2021 |
8.12.24 | 848,368 | 5/31/2021 |
8.12.23 | 251,093 | 5/13/2021 |
8.12.22 | 381,202 | 4/30/2021 |
8.12.21 | 365,900 | 4/8/2021 |
8.12.19 | 616,714 | 3/2/2021 |
8.12.18 | 500,498 | 2/10/2021 |
8.12.17 | 264,000 | 1/27/2021 |
8.12.16 | 148,654 | 1/15/2021 |
8.12.15 | 513,825 | 12/18/2020 |
8.12.14 | 326,167 | 12/4/2020 |
8.12.13 | 514,438 | 11/18/2020 |
8.12.11 | 1,095,595 | 10/9/2020 |
8.12.10 | 191,918 | 9/29/2020 |
8.12.9 | 416,147 | 9/2/2020 |
8.12.8 | 461,355 | 8/17/2020 |
8.12.7 | 514,766 | 7/21/2020 |
8.12.6 | 194,674 | 7/6/2020 |
8.12.5 | 2,652 | 7/6/2020 |
8.12.4 | 527,458 | 5/21/2020 |
8.12.3 | 202,503 | 5/8/2020 |
8.12.2 | 234,571 | 4/23/2020 |
8.12.1 | 532,325 | 3/31/2020 |
8.12.0 | 291,385 | 3/20/2020 |
8.11.5 | 313,246 | 3/3/2020 |
8.11.4 | 299,439 | 2/13/2020 |
8.11.3 | 287,646 | 2/3/2020 |
8.11.2 | 868,329 | 1/16/2020 |
8.11.1 | 399,680 | 12/12/2019 |
8.11.0 | 124,800 | 11/29/2019 |
8.10.23 | 94,975 | 11/18/2019 |
8.10.22 | 55,442 | 11/14/2019 |
8.10.21 | 438,945 | 10/17/2019 |
8.10.20 | 195,337 | 10/3/2019 |
8.10.19 | 194,701 | 9/21/2019 |
8.10.18 | 46,315 | 9/17/2019 |
8.10.17 | 295,230 | 8/16/2019 |
8.10.16 | 91,953 | 8/5/2019 |
8.10.15 | 199,902 | 7/18/2019 |
8.10.14 | 214,488 | 7/1/2019 |
8.10.13 | 448,404 | 5/31/2019 |
8.10.12 | 269,485 | 5/15/2019 |
8.10.11 | 84,865 | 5/7/2019 |
8.10.10 | 135,350 | 4/17/2019 |
8.10.9 | 254,215 | 4/5/2019 |
8.10.8 | 113,855 | 3/23/2019 |
8.10.7 | 148,326 | 3/11/2019 |
8.10.6 | 147,472 | 2/22/2019 |
8.10.5 | 488,468 | 2/8/2019 |
8.10.4 | 194,836 | 1/25/2019 |
8.10.3 | 136,851 | 1/11/2019 |
8.10.2 | 370,254 | 12/7/2018 |
8.10.1 | 64,979 | 11/29/2018 |
8.10.0 | 37,750 | 11/29/2018 |
8.9.16 | 530,465 | 10/19/2018 |
8.9.15 | 121,299 | 10/6/2018 |
8.9.14 | 93,366 | 9/21/2018 |
8.9.13 | 117,266 | 9/7/2018 |
8.9.12 | 227,470 | 8/25/2018 |
8.9.11 | 93,368 | 8/18/2018 |
8.9.10 | 316,717 | 7/12/2018 |
8.9.9 | 80,272 | 6/29/2018 |
8.9.8 | 71,269 | 6/15/2018 |
8.9.7 | 85,387 | 5/30/2018 |
8.9.6 | 131,429 | 5/16/2018 |
8.9.5 | 37,794 | 5/4/2018 |
8.9.4 | 107,341 | 4/17/2018 |
8.9.3 | 40,457 | 4/5/2018 |
8.9.2 | 72,451 | 3/19/2018 |
8.9.1 | 34,436 | 3/8/2018 |
8.9.0 | 49,762 | 2/22/2018 |
8.8.11 | 63,481 | 2/8/2018 |
8.8.10 | 36,918 | 1/25/2018 |
8.8.9 | 219,349 | 1/10/2018 |
8.8.8 | 149,670 | 12/8/2017 |
8.8.7 | 30,636 | 12/1/2017 |
8.8.6 | 69,179 | 11/17/2017 |
8.8.5 | 164,524 | 10/31/2017 |
8.8.4 | 139,028 | 10/17/2017 |
8.8.3 | 64,635 | 10/6/2017 |
8.8.2 | 50,538 | 9/22/2017 |
8.8.1 | 47,632 | 9/8/2017 |
8.8.0 | 118,407 | 8/22/2017 |
8.7.1 | 44,030 | 8/3/2017 |
8.7.0.1 | 55,991 | 7/21/2017 |
8.6.0.1 | 4,722 | 7/18/2017 |
8.6.0 | 43,218 | 7/10/2017 |
8.3.1.2 | 98,735 | 6/24/2017 |
8.3.1.1 | 128,626 | 3/13/2017 |
8.3.1 | 21,107 | 3/4/2017 |
7.7.4 | 337,747 | 11/13/2016 |
7.5.1 | 417,805 | 8/6/2016 |
7.2.5 | 447,635 | 2/11/2016 |
7.0.11 | 153,313 | 10/5/2015 |
7.0.9 | 82,603 | 8/16/2015 |
7.0.5.5 | 79,718 | 5/27/2015 |
7.0.5.4 | 3,209 | 5/23/2015 |
7.0.5.3 | 18,463 | 4/28/2015 |
7.0.5.1 | 3,019 | 4/27/2015 |
7.0.5 | 3,278 | 4/25/2015 |
4.10.0.62 | 305,088 | 8/21/2012 |
4.10.0.61 | 3,142 | 8/9/2012 |
4.10.0.59 | 3,316 | 7/27/2012 |
4.10.0.55 | 3,312 | 7/19/2012 |
4.9.0.52 | 3,222 | 7/13/2012 |
4.9.0.43 | 3,114 | 7/10/2012 |
4.9.0.42 | 3,234 | 7/9/2012 |
4.8.0.35 | 3,484 | 6/22/2012 |
4.8.0.33 | 4,091 | 6/16/2012 |
4.8.0.31 | 3,223 | 6/7/2012 |
4.8.0.30 | 3,946 | 5/31/2012 |
4.8.0.24 | 3,650 | 5/9/2012 |
4.7.0.21 | 4,510 | 4/28/2012 |
4.7.0.19 | 3,221 | 4/25/2012 |
4.6.0.16 | 3,557 | 3/30/2012 |
4.6.0.13 | 13,438 | 2/10/2012 |
4.5.0.9 | 6,950 | 1/30/2012 |
4.5.0.6 | 3,292 | 1/21/2012 |
4.5.0.4 | 4,170 | 1/20/2012 |
4.4.0.1 | 30,588 | 1/10/2012 |
3.8.0.400 | 3,354 | 11/28/2011 |
3.8.0.399 | 3,303 | 11/27/2011 |
3.8.0.394 | 3,352 | 11/24/2011 |
3.8.0.342 | 3,426 | 9/17/2011 |
3.7.1.342 | 3,322 | 9/17/2011 |
3.7.1.312 | 3,276 | 8/5/2011 |
3.7.1.306 | 13,221 | 8/5/2011 |