{"id":19099979,"url":"https://github.com/twcclegg/libphonenumber-csharp","last_synced_at":"2025-07-12T10:03:13.332Z","repository":{"id":36486623,"uuid":"40792214","full_name":"twcclegg/libphonenumber-csharp","owner":"twcclegg","description":"Offical C# port of https://github.com/googlei18n/libphonenumber","archived":false,"fork":false,"pushed_at":"2025-07-08T08:06:42.000Z","size":80905,"stargazers_count":845,"open_issues_count":7,"forks_count":159,"subscribers_count":26,"default_branch":"main","last_synced_at":"2025-07-08T09:25:44.897Z","etag":null,"topics":["csharp","e164","java-source","libphonenumber","phone-number","phonenumbers"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twcclegg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-08-15T23:46:33.000Z","updated_at":"2025-07-08T08:06:46.000Z","dependencies_parsed_at":"2023-01-17T02:00:54.732Z","dependency_job_id":"b6201fc7-c3e8-4cc3-ab20-96cf8563f1db","html_url":"https://github.com/twcclegg/libphonenumber-csharp","commit_stats":{"total_commits":839,"total_committers":41,"mean_commits":"20.463414634146343","dds":0.733015494636472,"last_synced_commit":"c8f5434d9eb74d29a2cf5328e8104117087ceed2"},"previous_names":["aidanbebbington/libphonenumber-csharp"],"tags_count":184,"template":false,"template_full_name":null,"purl":"pkg:github/twcclegg/libphonenumber-csharp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twcclegg%2Flibphonenumber-csharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twcclegg%2Flibphonenumber-csharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twcclegg%2Flibphonenumber-csharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twcclegg%2Flibphonenumber-csharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twcclegg","download_url":"https://codeload.github.com/twcclegg/libphonenumber-csharp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twcclegg%2Flibphonenumber-csharp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264972863,"owners_count":23691404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","e164","java-source","libphonenumber","phone-number","phonenumbers"],"created_at":"2024-11-09T03:52:24.927Z","updated_at":"2025-07-12T10:03:11.299Z","avatar_url":"https://github.com/twcclegg.png","language":"C#","funding_links":["https://www.buymeacoffee.com/tclegg"],"categories":["csharp"],"sub_categories":[],"readme":"[![Build status](https://ci.appveyor.com/api/projects/status/76abbk0qveot0mbo/branch/main?svg=true)](https://ci.appveyor.com/project/twcclegg/libphonenumber-csharp/branch/main)\n[![codecov](https://codecov.io/gh/twcclegg/libphonenumber-csharp/branch/main/graph/badge.svg)](https://codecov.io/gh/twcclegg/libphonenumber-csharp)\n[![NuGet](https://img.shields.io/nuget/dt/libphonenumber-csharp.svg)](https://www.nuget.org/packages/libphonenumber-csharp/)\n\nC# port of Google's [libphonenumber library](https://github.com/google/libphonenumber).\n\nThe code was rewritten from the Java source mostly unchanged, please refer to the original documentation for sample code and API documentation.\n\nThe original Apache License 2.0 was preserved.\n\nSee [this](csharp/README.md) for details about the port.\n\nPhone number metadata is updated in the Google repo approximately every two weeks. This library is automatically updated by a [scheduled github action](https://github.com/twcclegg/libphonenumber-csharp/actions/workflows/create_new_release_on_new_metadata_update.yml) to include the latest metadata, usually within a day.\n\n## Installation\n\nRun the following command to add this library to your project\n\n```\ndotnet add package libphonenumber-csharp\n```\n\nAvailable on NuGet as package [`libphonenumber-csharp`](https://www.nuget.org/packages/libphonenumber-csharp).\n\n## Examples\n\n### Parsing a phone number\n```csharp\nusing PhoneNumbers;\n\nvar phoneNumberUtil = PhoneNumberUtil.GetInstance();\nvar e164PhoneNumber = \"+44 117 496 0123\";\nvar nationalPhoneNumber = \"2024561111\";\nvar smsShortNumber = \"83835\";\nvar phoneNumber = phoneNumberUtil.Parse(e164PhoneNumber, null);\nphoneNumber = phoneNumberUtil.Parse(nationalPhoneNumber, \"US\");\nphoneNumber = phoneNumberUtil.Parse(smsShortNumber, \"US\");\n```\n\n### Formatting a phone number\n```csharp\nusing PhoneNumbers;\n\nvar phoneNumberUtil = PhoneNumberUtil.GetInstance();\nvar phoneNumber = phoneNumberUtil.Parse(\"+14156667777\", \"US\");\nvar formattedPhoneNumber = phoneNumberUtil.Format(phoneNumber, PhoneNumberFormat.INTERNATIONAL);\nvar formattedPhoneNumberNational = phoneNumberUtil.Format(phoneNumber, PhoneNumberFormat.NATIONAL);\n\nConsole.WriteLine(formattedPhoneNumber.ToString()); // +1 415-666-7777\nConsole.WriteLine(formattedPhoneNumberNational.ToString()); // (415) 666-7777\n```\n\n### Check if a phone number is valid\n```csharp\nusing PhoneNumbers;\n\nvar phoneNumberUtil = PhoneNumberUtil.GetInstance();\nvar phoneNumber = phoneNumberUtil.Parse(\"+14156667777\", \"US\");\nvar isValid = phoneNumberUtil.IsValidNumber(phoneNumber);\n\nConsole.WriteLine(isValid); // true\n```\n\n### Get the type of a phone number\n```csharp\nusing PhoneNumbers;\n\nvar phoneNumberUtil = PhoneNumberUtil.GetInstance();\nvar phoneNumber = phoneNumberUtil.Parse(\"+14156667777\", \"US\");\nvar numberType = phoneNumberUtil.GetNumberType(phoneNumber);\n\nConsole.WriteLine(numberType); // PhoneNumberType.FIXED_LINE_OR_MOBILE\n```\n\nSee [PhoneNumberType.cs](csharp/PhoneNumbers/PhoneNumberType.cs) for the various possible types of phone numbers\n\n### Get the region code for a phone number\n```csharp\nusing PhoneNumbers;\n\nvar phoneNumberUtil = PhoneNumberUtil.GetInstance();\nvar phoneNumber = phoneNumberUtil.Parse(\"+14156667777\", null);\nvar regionCode = phoneNumberUtil.GetRegionCodeForNumber(phoneNumber);\n\nConsole.WriteLine(regionCode); // US\n```\n\n## Features\n\n* Parsing/formatting/validating phone numbers for all countries/regions of the world.\n* 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).\n* IsNumberMatch - gets a confidence level on whether two numbers could be the same.\n* GetExampleNumber/GetExampleNumberByType - provides valid example numbers for 218 countries/regions, with the option of specifying which type of example phone number is needed.\n* IsPossibleNumber - quickly guessing whether a number is a possible phone number by using only the length information, much faster than a full validation.\n* AsYouTypeFormatter - formats phone numbers on-the-fly when users enter each digit.\n* FindNumbers - finds numbers in text input\n\nSee [PhoneNumberUtil.cs](csharp/PhoneNumbers/PhoneNumberUtil.cs) for the various methods and properties available.\n\n## Why keep libphonenumber-csharp up to date?\nA lot of the functionality depends on updated metadata that is published by the google repository, see example [here](https://github.com/google/libphonenumber/releases/tag/v8.13.55).\n\nThis 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\n\nTherefore, 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.\n\nFor more information on metadata usage, please refer to the [main repository faq](https://github.com/google/libphonenumber/blob/master/FAQ.md#metadata)\n\n## ToDo\n\n* port read / write source xml data to binary for better performance and smaller .nupkg size (WIP)\n* update / add / port new unit tests and logging from java source\n\n## How to unfold automatic generated files\n\n* Install Jetbrains - Resharper for Visual Studio\n* File by file, right click and \"Cleanup code\"\n* Check the unfolded file\n\n## Running tests locally\n\nTo run tests locally, you will need a zip version of the `geocoding.zip` file stored in the `resources` folder\nand `testgeocoding.zip` file stored in the `resources/test` folder.\n\nOn linux, you can run the following commands to generate the zip accordingly\n\n```bash\n(cd resources/geocoding; zip -r ../../resources/geocoding.zip *)\n(cd resources/test/geocoding; zip -r ../../../resources/test/testgeocoding.zip *)\n```\n\nFor windows, you can use the following powershell script\n\n```powershell\nCompress-Archive -Path \"resources\\geocoding\\*\" -DestinationPath \"resources\\geocoding.zip\"\nCompress-Archive -Path \"resources\\test\\geocoding\\*\" -DestinationPath \"resources\\test\\testgeocoding.zip\"\n```\n\n## Contributing\nSee [CONTRIBUTING.md](CONTRIBUTING.md)\n\n## Donations\n\n[![Buy me a beer](https://raw.githubusercontent.com/twcclegg/libphonenumber-csharp/main/bmacButton.png)](https://www.buymeacoffee.com/tclegg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwcclegg%2Flibphonenumber-csharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwcclegg%2Flibphonenumber-csharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwcclegg%2Flibphonenumber-csharp/lists"}