Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build_and_run_unit_tests_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
run: |
(cd resources/geocoding; zip -r ../../resources/geocoding.zip *)
(cd resources/test/geocoding; zip -r ../../../resources/test/testgeocoding.zip *)
(cd resources/test/carrier; zip -r ../../../resources/test/testcarrier.zip *)
- name: Restore dependencies
run: dotnet restore
working-directory: ./csharp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
run: |
Compress-Archive -Path "resources\geocoding\*" -DestinationPath "resources\geocoding.zip"
Compress-Archive -Path "resources\test\geocoding\*" -DestinationPath "resources\test\testgeocoding.zip"
Compress-Archive -Path "resources\test\carrier\*" -DestinationPath "resources\test\testcarrier.zip"
- name: Run tests
run: dotnet test csharp/PhoneNumbers.sln --configuration Release --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage
- name: Upload coverage reports to Codecov
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ FakesAssemblies/
# Zipped Geocoding Data
geocoding.zip
testgeocoding.zip
/resources/carrier.zip
/resources/test/testcarrier.zip

# Performance tests artifacts
csharp/PhoneNumbers.PerformanceTest/BenchmarkDotNet.Artifacts/
Expand Down
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ var regionCode = phoneNumberUtil.GetRegionCodeForNumber(phoneNumber);
Console.WriteLine(regionCode); // US
```

### Get the carrier name for a phone number
```csharp
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); // Vodafone
Comment thread
wmundev marked this conversation as resolved.
```

> **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 `GetSafeDisplayName` to return an empty string in those regions.

## Features

* Parsing/formatting/validating phone numbers for all countries/regions of the world.
Expand All @@ -94,6 +108,7 @@ Console.WriteLine(regionCode); // US
* 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](csharp/PhoneNumbers/PhoneNumberUtil.cs) for the various methods and properties available.

Expand All @@ -119,21 +134,31 @@ For more information on metadata usage, please refer to the [main repository faq

## 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.
To run tests locally, you will need zip versions of the geocoding and carrier data files.

| Zip file | Source directory |
|---|---|
| `resources/geocoding.zip` | `resources/geocoding/` |
| `resources/carrier.zip` | `resources/carrier/` |
| `resources/test/testgeocoding.zip` | `resources/test/geocoding/` |
| `resources/test/testcarrier.zip` | `resources/test/carrier/` |

On linux, you can run the following commands to generate the zip accordingly
On linux, you can run the following commands to generate the zips accordingly

```bash
(cd resources/geocoding; zip -r ../../resources/geocoding.zip *)
(cd resources/carrier; zip -r ../../resources/carrier.zip *)
(cd resources/test/geocoding; zip -r ../../../resources/test/testgeocoding.zip *)
(cd resources/test/carrier; zip -r ../../../resources/test/testcarrier.zip *)
```

For windows, you can use the following powershell script

```powershell
Compress-Archive -Path "resources\geocoding\*" -DestinationPath "resources\geocoding.zip"
Compress-Archive -Path "resources\carrier\*" -DestinationPath "resources\carrier.zip"
Compress-Archive -Path "resources\test\geocoding\*" -DestinationPath "resources\test\testgeocoding.zip"
Compress-Archive -Path "resources\test\carrier\*" -DestinationPath "resources\test\testcarrier.zip"
```

## Contributing
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ branches:
before_build:
- dotnet restore csharp -s https://api.nuget.org/v3/index.json
- ps: Compress-Archive -Path "resources\geocoding\*" -DestinationPath "resources\geocoding.zip"
- ps: Compress-Archive -Path "resources\carrier\*" -DestinationPath "resources\carrier.zip"
- ps: Compress-Archive -Path "resources\test\geocoding\*" -DestinationPath "resources\test\testgeocoding.zip"
Comment thread
wmundev marked this conversation as resolved.
- ps: Compress-Archive -Path "resources\test\carrier\*" -DestinationPath "resources\test\testcarrier.zip"
build_script:
- dotnet pack -c Release csharp\PhoneNumbers
- dotnet pack -c Release csharp\PhoneNumbers.Extensions
Expand Down
2 changes: 2 additions & 0 deletions csharp/PhoneNumbers.Test/PhoneNumbers.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@

<ItemGroup>
<EmbeddedResource Include="..\..\resources\PhoneNumberMetadataForTesting.xml" />
<EmbeddedResource Include="..\..\resources\test\carrier\**" LinkBase="carrier" />
<EmbeddedResource Include="..\..\resources\test\geocoding\**" LinkBase="geocoding" />
<EmbeddedResource Include="..\..\resources\test\testgeocoding.zip" />
<EmbeddedResource Include="..\..\resources\test\testcarrier.zip" />
Comment thread
wmundev marked this conversation as resolved.
</ItemGroup>

<ItemGroup>
Expand Down
Loading