GlobalPhone 6.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package GlobalPhone --version 6.0.0                
NuGet\Install-Package GlobalPhone -Version 6.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GlobalPhone" Version="6.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GlobalPhone --version 6.0.0                
#r "nuget: GlobalPhone, 6.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GlobalPhone as a Cake Addin
#addin nuget:?package=GlobalPhone&version=6.0.0

// Install GlobalPhone as a Cake Tool
#tool nuget:?package=GlobalPhone&version=6.0.0                

GlobalPhone Build Status Build status

GlobalPhone parses, validates, and formats local and international phone numbers according to the E.164 standard.

Store and display phone numbers in your app. Accept phone number input in national or international format. Convert phone numbers to international strings (+13125551212) for storage and retrieval. Present numbers in national format ((312) 555-1212) in your UI.

Designed with the future in mind. GlobalPhone uses the c# implementation based on Google's open-source libphonenumber database.

Installation

  1. Add the GlobalPhone nuget package to your app. For example, using Package Manager Console:

     PM> Install-Package GlobalPhone
    

Or you can add it as a solution level package.

Examples

Parse an international number string into a GlobalPhone::Number object:

var number = GlobalPhone.Parse("+1-312-555-1212");
# => #{GlobalPhone::Number +13125551212}

Query the country code and likely territory name of the number:

number.CountryCode
# => 1

number.RegionCode
# => "US"

Present the number in national and international formats:

number.NationalFormat
# => "(312) 555-1212"

number.InternationalFormat
# => "+1 312-555-1212"

Is the number valid? (Note: this is not definitive. For example, the number here is "IsValid" by format, but there are no US numbers that start with 555. The IsValid method may return false positives, but should not return false negatives unless the database is out of date.)

number.IsValid
# => true

Get the number's normalized E.164 international string:

number.InternationalString
# => "+13125551212"

Parse a number in national format for a given territory:

number = GlobalPhone.Parse("(0) 20-7031-3000", "gb");
# => #{GlobalPhone::Number +442070313000}

Parse an international number using a territory's international dialing prefix:

number = GlobalPhone.Parse("00 1 3125551212", "gb");
# => #{GlobalPhone::Number +13125551212}

Set the default territory to Great Britain (territory names are ISO 3166-1 Alpha-2 codes):

GlobalPhone.DefaultTerritoryName = "gb";
# => "gb"

GlobalPhone.Parse("(0) 20-7031-3000");
# => #{GlobalPhone::Number +442070313000}

Shortcuts for validating a phone number:

GlobalPhone.Validate("+1 312-555-1212");
# => true

GlobalPhone.Validate("+442070313000");
# => true

GlobalPhone.Validate("(0) 20-7031-3000");
# => false

GlobalPhone.Validate("(0) 20-7031-3000", "gb");
# => true

Shortcuts for normalizing a phone number in E.164 format:

GlobalPhone.Normalize("(312) 555-1212");
# => "+13125551212"

GlobalPhone.Normalize("+442070313000");
# => "+442070313000"

string normalized;
GlobalPhone.TryNormalize("(0) 20-7031-3000", out normalized);
# => false

GlobalPhone.Normalize("(0) 20-7031-3000");
# => #{PhoneNumbers::NumberParseException}

GlobalPhone.Normalize("(0) 20-7031-3000", "gb");
# => "+442070313000"

Caveats

GlobalPhone currently does not parse emergency numbers or SMS short code numbers.

Validation is not definitive and may return false positives, but should not return false negatives unless the database is out of date.

Territory heuristics are imprecise. Parsing a number will usually result in the territory being set to the primary territory of the region. For example, Canadian numbers will be parsed with a territory of US. (In most cases this does not matter, but if your application needs to perform geolocation using phone numbers, GlobalPhone may not be a good fit.)

Development

The GlobalPhone source code is hosted on GitHub. You can check out a copy of the latest code using Git:

CMD> git clone https://github.com/GlobalPhone/GlobalPhone.git

If you've found a bug or have a question, please open an issue on the issue tracker. Or, clone the GlobalPhone repository, write a failing test case, fix the bug, and submit a pull request.

GlobalPhone is a port of Sam Stephenson GlobalPhone for ruby hosted on GitHub.

License

Copyright © 2013 Sam Stephenson, Oskar Gewalli

Released under the MIT license. See LICENSE for details.

Product 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 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. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  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 tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
6.0.1 48,358 10/31/2019
6.0.0 35,898 9/23/2018
5.0.2 16,160 7/20/2016
5.0.1 1,506 7/11/2016
5.0.0 1,297 7/11/2016
4.0.1 4,179 6/8/2016
4.0.0 1,313 6/8/2016
3.1.3 1,173 6/8/2016
3.1.2 1,130 6/4/2016
3.1.1 1,156 6/3/2016
3.0.0 1,344 6/1/2016
2.0.2 3,843 12/15/2014
2.0.1 1,463 12/5/2014
2.0.0 1,369 12/3/2014
1.3.0 4,170 9/16/2014
1.2.2 1,399 7/8/2014
1.2.1 118,218 3/31/2014
1.1.1 1,350 2/28/2014
1.1.0 1,346 2/28/2014
1.0.6 1,344 1/3/2014
1.0.5 1,312 10/29/2013
1.0.4 1,323 10/27/2013
1.0.3 1,290 10/27/2013
1.0.2 1,372 10/27/2013
1.0.1 1,352 10/27/2013

Reimplemented as wrapper around libphonenumber-csharp