libphonenumber-csharp
9.0.36
Prefix Reserved
dotnet add package libphonenumber-csharp --version 9.0.36
NuGet\Install-Package libphonenumber-csharp -Version 9.0.36
<PackageReference Include="libphonenumber-csharp" Version="9.0.36" />
<PackageVersion Include="libphonenumber-csharp" Version="9.0.36" />
<PackageReference Include="libphonenumber-csharp" />
paket add libphonenumber-csharp --version 9.0.36
#r "nuget: libphonenumber-csharp, 9.0.36"
#:package libphonenumber-csharp@9.0.36
#addin nuget:?package=libphonenumber-csharp&version=9.0.36
#tool nuget:?package=libphonenumber-csharp&version=9.0.36
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.
Try the interactive demo → — parse, format, validate, and find phone numbers in your browser. No install required; runs entirely via WebAssembly.
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. See Metadata updates for how that works and how to run it manually.
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
Get the time zones for a phone number
using PhoneNumbers;
var phoneNumberUtil = PhoneNumberUtil.GetInstance();
var timeZonesMapper = PhoneNumberToTimeZonesMapper.GetInstance();
var phoneNumber = phoneNumberUtil.Parse("+12128120000", null);
var timeZones = timeZonesMapper.GetTimeZonesForNumber(phoneNumber);
Console.WriteLine(string.Join(", ", timeZones)); // America/New_York
Returns a List<string> of IANA time zone identifiers. For numbers that span multiple time zones (e.g. a country-level lookup), the list will contain more than one entry. Returns ["Etc/Unknown"] for invalid or unrecognised numbers.
Use GetTimeZonesForGeographicalNumber instead if you have already validated the number and want to skip the internal type check.
Get the carrier name for a phone number
using PhoneNumbers;
var phoneNumberUtil = PhoneNumberUtil.GetInstance();
var carrierMapper = PhoneNumberToCarrierMapper.GetInstance();
var phoneNumber = phoneNumberUtil.Parse("+917503397672", null);
var carrierName = carrierMapper.GetNameForNumber(phoneNumber, Locale.English);
Console.WriteLine(carrierName); // Aircel
Note: Carrier data reflects the original network allocation. If the country supports mobile number portability, the number may have since moved to a different carrier. Use
GetSafeDisplayNameto return an empty string in those regions.
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
- PhoneNumberToCarrierMapper - looks up the carrier name originally assigned to a mobile or pager number, with locale-aware output and a safe-display mode for regions with mobile number portability.
See PhoneNumberUtil.cs for the various methods and properties available.
Why keep libphonenumber-csharp up to date?
A lot of the functionality depends on updated metadata that is published by the google repository, see example here.
This means that if you don't keep the package up to date, methods like IsValidNumber will return false for newer numbers that rely on the updated metadata
Therefore, we recommend you keep this nuget package as up to date as possible using automated means (such as dependabot) as metadata changes published by the google repository is frequent, usually a few times a month.
For more information on metadata usage, please refer to the main repository faq
ToDo
- 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
dotnet test csharp/PhoneNumbers.sln
Metadata updates
The create_new_release_on_new_metadata_update workflow runs daily and drives lib/github-actions-metadata-update.sh. When the latest google/libphonenumber release is newer than the published NuGet package, it copies the upstream resources/, regenerates csharp/PhoneNumbers/LocaleData.cs, builds and tests, then commits, pushes and creates a matching GitHub release.
Before doing any of that it inspects the upstream diff and stops if it contains .java or .proto files, because changes to the Java sources may need porting by hand and an unattended metadata bump would silently skip them.
Skipping the java (or proto) check
If you have reviewed the upstream diff and the Java changes don't need porting (for example test-only or build-file changes), you can run the update anyway:
From the Actions UI — open create_new_release_on_new_metadata_update, click Run workflow, and tick skip_java_check (and/or skip_proto_check). Scheduled runs always leave both unticked.
Locally — pass the flag or set the environment variable:
bash lib/github-actions-metadata-update.sh --skip-java-check "$GITHUB_TOKEN" # or SKIP_JAVA_CHECK=true bash lib/github-actions-metadata-update.sh "$GITHUB_TOKEN"--skip-proto-check/SKIP_PROTO_CHECKwork the same way, and--helplists every option.
Skipping a check means the release ships upstream metadata from a version whose Java-side changes were not ported, so read the upstream diff first — the script prints the offending filenames before it stops.
Dry runs
--dry-run (or the dry_run workflow input) runs every read-only step — version lookups, repository checks, the upstream diff gates, the upstream clone — reports what a real run would do, and stops before the first change to the working tree. Nothing is copied, generated, committed, pushed or released, no token is required, and the clean-main requirement is relaxed to a warning so it works from a feature branch:
# what would tonight's scheduled run do?
bash lib/github-actions-metadata-update.sh --dry-run
UPSTREAM_TAG and DEPLOYED_VERSION override the two version lookups, which lets you replay any historical release pair — useful for seeing how a given release trips the gates:
UPSTREAM_TAG=v9.0.33 DEPLOYED_VERSION=9.0.32 \
bash lib/github-actions-metadata-update.sh --dry-run
Running it against a fork
Nothing about the target repository is hard-coded. The script commits and pushes through whatever checkout it runs in, and takes the repository to release from GITHUB_REPOSITORY — set automatically by GitHub Actions, and otherwise derived from the origin remote. So a fork releases to itself, and the dry-run summary names the repository it would publish to. UPSTREAM_REPOSITORY (default google/libphonenumber) and NUGET_PACKAGE_ID (default libphonenumber-csharp) are overridable the same way.
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. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .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 (>= 8.0.0)
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (220)
Showing the top 5 NuGet packages that depend on libphonenumber-csharp:
| Package | Downloads |
|---|---|
|
N3O.Umbraco.Validation
TODO |
|
|
OrchardCore.Infrastructure
Orchard Core CMS is a Web Content Management System (CMS) built on top of the Orchard Core Framework. Implementation for OrchardCoreCMS Infrastructure |
|
|
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. |
|
|
mmx.utils
Package Description |
|
|
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. |
GitHub repositories (9)
Showing the top 9 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.
|
|
|
shrimqy/Sefirah
Phone Link / KDE Connect alternative
|
|
|
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.
|
|
|
moeacgx/Telegram-Panel
Telegram多账号多功能管理面板
|
|
|
shr670377723/CommunityServer-master
|
|
|
Altinn/altinn-studio
Next generation open source Altinn platform and applications.
|
|
|
SaaStacked/saastack
A comprehensive codebase template for starting your real-world, fully featured SaaS web products. On the .NET platform
|
| Version | Downloads | Last Updated |
|---|---|---|
| 9.0.36 | 0 | 8/3/2026 |
| 9.0.35 | 142,252 | 7/17/2026 |
| 9.0.34 | 193,298 | 7/3/2026 |
| 9.0.33 | 207,164 | 6/22/2026 |
| 9.0.32 | 352,138 | 6/5/2026 |
| 9.0.31 | 389,653 | 5/23/2026 |
| 9.0.30 | 386,230 | 5/7/2026 |
| 9.0.29 | 336,534 | 4/25/2026 |
| 9.0.28 | 352,124 | 4/14/2026 |
| 9.0.27 | 245,611 | 4/2/2026 |
| 9.0.26 | 560,125 | 3/14/2026 |
| 9.0.25 | 387,705 | 2/27/2026 |
| 9.0.24 | 393,294 | 2/14/2026 |
| 9.0.23 | 513,979 | 1/30/2026 |
| 9.0.22 | 641,617 | 1/16/2026 |
| 9.0.21 | 766,734 | 12/18/2025 |
| 9.0.20 | 417,892 | 12/5/2025 |
| 9.0.19 | 571,823 | 11/20/2025 |
| 9.0.18 | 465,518 | 11/7/2025 |
| 9.0.17 | 438,755 | 10/24/2025 |
