GlobalPhone 6.0.0

Package Description

Install-Package GlobalPhone -Version 6.0.0
dotnet add package GlobalPhone --version 6.0.0
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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 &copy; 2013 Sam Stephenson, Oskar Gewalli

Released under the MIT license. See LICENSE for details.

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 &copy; 2013 Sam Stephenson, Oskar Gewalli

Released under the MIT license. See LICENSE for details.

Release Notes

Reimplemented as wrapper around libphonenumber-csharp

Version History

Version Downloads Last updated
6.0.0 3,447 9/23/2018
5.0.2 10,130 7/20/2016
5.0.1 560 7/11/2016
5.0.0 385 7/11/2016
4.0.1 649 6/8/2016
4.0.0 255 6/8/2016
3.1.3 268 6/8/2016
3.1.2 260 6/4/2016
3.1.1 251 6/3/2016
3.0.0 255 6/1/2016
2.0.2 2,249 12/15/2014
2.0.1 314 12/5/2014
2.0.0 314 12/3/2014
1.3.0 1,069 9/16/2014
1.2.2 472 7/8/2014
1.2.1 5,469 3/31/2014
1.1.1 361 2/28/2014
1.1.0 320 2/28/2014
1.0.6 390 1/3/2014
1.0.5 373 10/29/2013
1.0.4 368 10/27/2013
1.0.3 356 10/27/2013
1.0.2 370 10/27/2013
1.0.1 364 10/27/2013