twcclegg / libphonenumber-csharp Goto Github PK
View Code? Open in Web Editor NEWOffical C# port of https://github.com/googlei18n/libphonenumber
License: Apache License 2.0
Offical C# port of https://github.com/googlei18n/libphonenumber
License: Apache License 2.0
PhoneNumberUtil phoneUtil = PhoneNumberUtil.GetInstance(); var all = phoneUtil.GetSupportedGlobalNetworkCallingCodes();
all will be an empty dictionary while it should return the full list of supported calling code metadata
In Phonenumber.cs
, the protobuff defined 2 classes with virtually the same name except for casing.
public static partial class Phonenumber
public partial class PhoneNumber
This is preventing me from using the libphonenumber-csharp library in a VB.NET project (VB.NET being case insensitive, throws the error error BC30560: 'PhoneNumber' is ambiguous in the namespace 'PhoneNumbers'.
).
I could fix and build the reference myself, but would love to be able to use the Nuget package instead. Think this is something you'd consider fixing? (I'll see if I can carve some time tomorrow to fix it on my own and submit a PR).
Example of a Solomon island number:
+677 (71) 52398
I'm using 8.9.10 net40
Happy to provide whatever you need!
NZ now allows 7 or 8 digits after the network code.
The library is failing the validation when 8 chars after the network code.
See below for example number that fails:
Fails (but is valid - see here: http://www.tnzi.com/numbering-plan)
+642123456789
I'm trying to match x
telephone numbers across the whole address book (which can contain y
contacts and z
telephone numbers - i.e. multiple phones per contact).
See #84 for code excerpt (even though this issue is about getting an exception on an iOS device which is something quite different than the question I'm asking here).
Issuing multiple calls to IsNumberMatch is super slow.
Possibly because new Regex objects have to be created each time.
It wonder if it would be (a lot?) faster if we had at least a method that would take a collection of strings to match as in
public MatchType IsNumberMatch(IList<string> firstNumbers, string secondNumber)
I know your library is a 1 to 1 mapping from the original one from Google so I guess it is unlikely you would like to add this to it until Google does so eventually.
So before cloning your repo and trying to add some custom code, I wanted to know if you think this is feasible and if it would help speed up things by not re-creating multiple objects... as in https://stackoverflow.com/questions/39470506/c-sharp-regex-performance-very-slow for instance.
Hi,
Please check following numbers if they produce consistent output, throw exception, etc...
00870773924761
00211912378429
Thanks
I'm comparing the output to what I get from here: http://rawgit.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/demo-compiled.html
Very simple code, just doing the followig:
PhoneNumberUtil util = PhoneNumberUtil.GetInstance();
PhoneNumber test = util.Parse("044 668 18 00", "CH");
//PhoneNumber test = util.Parse("0111 111 1111", "GB");
Debug.Print(util.Format(test, PhoneNumberFormat.NATIONAL));
(Both versions cause the issue).
I am expecting the output to be "044 668 18 00" but instead it is "0446681800"
I went back to hash fa23720 and it seemed to be working properly there
Could you update a Project Site url on the nugt package page https://www.nuget.org/packages/libphonenumber-csharp? Currently, it is pointing to the old bitbucket repository which is confusing, because the repository has not been updated since 2012, but 12 new nuget packages have been published since then.
Hi, I've tried to use this lib, but, accidently met some problems with some numbers (RU region),
for example, number like '7 016 1610088' or '7 001 1610088'
First of my thoughts was because of your inner formats, in which this parts are stored (string would be greatest solution to keep at least national number part), but we have what we have, so let's go on and
Second, is that with numbers like that NDC returned as 0 because of this function:
GetLengthOfNationalDestinationCode - internal realization has its array variable, which in this cases is
about length of 2 elements, and code inside written like
if (array.Length <= 3)
{
return 0;
}
It's all rooted deep inside of all code of lib, but, may you give me some thoughts about how to solve that problem?
Hello,
I tried updating a PCL project to .NET standard after removing this package and then tried reinstalling this package from nuget after changing to .NET standard. This package will not install for some reason. FYI
https://docs.microsoft.com/en-us/dotnet/articles/standard/library
Thank you for this package by the way!!!
After the update to the last version (from 8.3.1 to 8.3.1.1) using NuGet, Visual Studio compiler raises error CS0012 in my project, looking for System.Runtime.
The type 'type' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime', Version=4.0.0.0, Culture=neutral
The downgrade to version 8.3.1 works fine.
I'm using .Net 4.0 (not client)
I'm using this library for a uwp project.
The Java counterpart works fine with the PhoneNumberUtil.getInstance().parse("phonenumber here","") format, automatically determining the country code. However the .Net version (this) requires a valid country identifier, which I unfortunately do not have specified for the phone numbers.
How can I do this with this library?
❤️ I just wanna thank you for the port.
Sorry for spamming.
Hi
I am using lib for Web App. Which is hosted via IIS. If IIS is idle for some time(No request are coming) it will start GC and after if any new request comes "PhoneNumberUtil.GetInstance()" will take 2 to 3 sec to re initialize. Can It be optimize some how?
Thanks.
I have an error when the nuget is added to a Xamarin Android app through a netstandard project (ie: a netstandard 2.0 project reference the libphonenumber nuget, and the android project reference the netstandard 2 project):
Xamarin.Android.Common.targets(1397,2): error : Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'PhoneNumbers, Version=8.8.3.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
I suppose the manifest file should not contain a "runtime" entry, but a "reference" entry instead as explained here.
"runtime": {
"PhoneNumbers.dll": {}
}
Adding libphonenumber as a direct dependency to the Android project does fix the problem.
Hi @aidanbebbington,
Thanks for your work on this port of library. I want to ask this because I need the PhoneNumberToCarrierMapper and PhoneNumberToTimeZonesMapper classes, which is not found in this port. Or is there anyone else you guys try to present these classes in this port. If I want add these classes on this repository, can you please guide me to do that.
Thanks.
Hi,
I am having thread safety issues with IsNumberMatch.
At least on Xamarin.iOS - haven't test yet on plain .NET.
The following (excerpt) code (running on Xamarin.iOS) :
var phoneNumberUtil = PhoneNumberUtil.GetInstance();
SynchronizedCollection<Contact> contactList = new SynchronizedCollection<Contact>();
// Assume AddressBook is a List<T> (where T is a Contact object)
// already filled with the user's address book:
Parallel.ForEach(AddressBook, c =>
{
if (c.Numbers == null || c.Numbers.Count == 0)
return;
foreach (var n in c.Numbers)
{
var m = phoneNumberUtil.IsNumberMatch(phoneNumber, n);
if (m == PhoneNumberUtil.MatchType.NOT_A_NUMBER
|| m == PhoneNumberUtil.MatchType.NO_MATCH)
continue;
else
contactList.Add(c);
}
}
);
generates the following exception:
System.NullReferenceException: Object reference not set to an instance of an object
with the following stack trace:
RegexInterpreter.Go ()
RegexRunner.Scan (System.Text.RegularExpressions.Regex regex, System.String text, System.Int32 textbeg, System.Int32 textend, System.Int32 textstart, System.Int32 prevlen, System.Boolean quick, System.TimeSpan timeout)
Regex.Run (System.Boolean quick, System.Int32 prevlen, System.String input, System.Int32 beginning, System.Int32 length, System.Int32 startat)
Regex.Match (System.String input)
PhoneNumberUtil.ExtractPossibleNumber (System.String number)
PhoneNumberUtil.BuildNationalNumberForParsing (System.String numberToParse, System.Text.StringBuilder nationalNumber)
PhoneNumberUtil.ParseHelper (System.String numberToParse, System.String defaultRegion, System.Boolean keepRawInput, System.Boolean checkRegion, PhoneNumbers.PhoneNumber+Builder phoneNumber)
PhoneNumberUtil.Parse (System.String numberToParse, System.String defaultRegion, PhoneNumbers.PhoneNumber+Builder phoneNumber)
PhoneNumberUtil.Parse (System.String numberToParse, System.String defaultRegion)
PhoneNumberUtil.IsNumberMatch (System.String firstNumber, System.String secondNumber)
ContactServiceImplementation+<>c__DisplayClass3_0.<FindContactsByPhoneNumber>b__0 (Plugin.ContactService.Shared.Contact c)
Parallel+<>c__DisplayClass31_0`2[TSource,TLocal].<ForEachWorker>b__0 (System.Int32 i)
Parallel+<>c__DisplayClass17_0`1[TLocal].<ForWorker>b__1 ()
Task.InnerInvoke ()
Task.InnerInvokeWithArg (System.Threading.Tasks.Task childTask)
Task+<>c__DisplayClass178_0.<ExecuteSelfReplicating>b__0 (System.Object <p0>)
Am I doing something wrong?
Same code in a classic foreach
loop works flawlessly.
Thanks
Being the most often updated and most popular port of libphonenumber to C#, this port is currently considered to be the port of choice in the long term for a project which requires strong names for all its component DLLs. Therefore, we would be very thankful if the DLLs could be made strongly named, so that it could be used for a wider range of projects with higher requirements for safety. Thank you in advance!
When I have a number starting with 0046 the phonenumber util does not recognize this number as a vaild swedish number. Instead of + before nationalcode there is 00
Exampel
"0046081231234"
hi, can you give me write access to this repository and the nuget-package? my nuget account is "landrix" thanks, Sven
Wouldn't it be easier for developers if we could replace the JavaDoc comments to XML Documentation comments?
When using this library, this change would make it possible to read the comments in the IDE instead of having lookup the source code in the repo.
Examples:
161 525 5628 or +44 161 525 5628
161 509 5085 or +44 161 509 5085
Both IsValidNumber(phone) and IsValidNumberForRegion(phone, RegionCode.GB) returning false for the phones above.
Google demo call validates them as correct phones.
Note that there are no problems with phones starting from 161 4 (or any other digit here except 5)
Please update metadata from 7.0.11 to 7.4.1 (google/libphonenumber@ada9fd4)
When I install this lib by NuGet in the UWP project, I get the error message: "Some packages are not compatible with UAP,Version=v10.0"
Please check the following code:
var u = PhoneNumberUtil.GetInstance();
var parsed = u.Parse("+29022158", null); // The sample code provided by metadata for SH.
u.IsPossibleNumberWithReason(parsed); // will return TOO_LONG.
In the phone metadata description under ./resources folder. The description is:
<!-- St Helena has changed to 5 digits on October 1. 2013 -->
<generalDesc>
<nationalNumberPattern>[256]\d{4}</nationalNumberPattern>
<possibleNumberPattern>\d{4,5}</possibleNumberPattern>
</generalDesc>
while the counterpart in the embedded resource for PhoneNumber.dll is:
<generalDesc>
<nationalNumberPattern>[2-9]\d{3}</nationalNumberPattern>
<possibleNumberPattern>\d{4}</possibleNumberPattern>
</generalDesc>
It would be nice to have version usable from portable projects (including UWP)
Hi
There is currently a port of the Ruby Gem GlobalPhone in c#. Would it make sense to deprecate GlobalPhone (since there has not been any interest in making any pull requests) and point to libphonenumber-csharp? This is related to GlobalPhone/GlobalPhone#24
Hello,
We currently use the library to get country code for each available regions like this:
var uti = PhoneNumberUtil.GetInstance();
var regions = new ObservableCollection<CountryPhone>();
foreach (var region in uti.GetSupportedRegions())
{
var val = uti.GetCountryCodeForRegion(region);
regions.Add(new CountryPhone
{
// ...
});
}
But this takes a long time the first time.
Isn't there a way to get all the CountryCode for one shot?
Hello,
The short number functionality is missing from the library.
In the original library or using this checker:
https://libphonenumber.appspot.com/phonenumberparser?number=911&country=US
For example, if I want to check if 911 is a valid number, then it says that is INVALID.
But if I see the short number results they say that it is a valid short number.
The library only has two function and is missing the others that are really useful:
isPossibleShortNumber()
isValidShortNumber()
isPossibleShortNumberForRegion()
isValidShortNumberForRegion()
Please help adding this functionality!
Thank you in advance
I recently upgraded an app of mine to ASP.NET 5 .NET Core, then realised that this great library didn't support DNXCore.
Is this support coming soon?
I believe the google code was updated to support the new toll free 833 area code. Can the c# version be updated as well asap?
Thank you.
var phoneNumber = utility.Parse(mobNo, region);
This library doesn't support personal numbering.
https://en.wikipedia.org/wiki/Personal_numbering
I'm trying with Spain's numbers, for example: +345906xxxxxxxxx it doesn't recognize them
Love the package but are there any plans to release a strong named version in the near future? Our project is strong named (due to upstream requirements) and we are unable to consume this unless it's also strong named.
I am aware of workarounds such as signing the assembly ourselves (or forking the project), but am hoping for something cleaner and less intrusive.
Thanks!
var _util = PhoneNumberUtil.GetInstance();
var result = _util.Verify(PhoneNumberUtil.Leniency.VALID, number, str, _util);
Is the intent for this to be:
var _util = PhoneNumberUtil.GetInstance();
var result = PhoneNumberUtil.Verify(PhoneNumberUtil.Leniency.VALID, number, str, _util);
or
var _util = PhoneNumberUtil.GetInstance();
var result = _util.Verify(PhoneNumberUtil.Leniency.VALID, number, str);
?
ilibphonenumber for VB.Net: where can I download the latest version
Over time as new area codes are added and the version of this package changes I am forced to recompile to properly reference the new version of the dll.
I don't think the logic behind this lookup should change with the addition of area codes.
It seems the region information (in libphonenumber-csharp-master\csharp\PhoneNumbers\res) is not updated- and we should take those region files from the Java version.
The C# version of libphonenumber has regional information about 87 countries, while the Java version has information about 130 countries.
Additionally, the C# region files are older than the Java region files, so it possible to find differences in region files who exists in both versions.
Hi, I am using your library in one of our project with Xamarin.iOS.
We are using AsYouTypeFormatter with our textfields.
But I did not found a way to remove last character from AsYouTypeFormatter.
We have backspace option in keyboard to delete last character but i did not find a way to delete character with this formatter.
Need help.
Hi,
I just updated an old project to a newer version 8.9.15 from 7.5.1.
Currently the PhoneNumberUtil.GetInstance() fails with error Could not find file 'C:\...\bin\Debug\PhoneNumbers.PhoneNumberMetaData.xml'
.
So it's now mandatory to place the PhoneNumberMetaData.xml in the output folder?
I though that metadata was embedded in the dll.
Maybe example should be updated if xml is not embedded any more?
Thanks!
Attempting to use this library in a Xamarin Forms mobile application and I'm getting the error:
Severity Code Description Project File Line Suppression State Error Could not install package 'libphonenumber-csharp 8.9.5'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile78', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
Any obvious reasons for this, My assumption is that my project needs to be updated to support .net standard 2.0
i want to update to version 7.7.4
what steps are needed?
i've updated the ressources and generated new phonenumber.cs and phonemetadata.cs
whats next?
Hi,
First of all thanks for porting to C#. Most of the ported API is working properly for my use case. But the metadata is changing frequently on https://github.com/googlei18n/libphonenumber. If you show me how to update metadata I will keep posting PR with updated metadata.
Thanks
numberToParse = "61 (2) 22333"
defaultRegion = "AU"
It returns 6161222333 instead of the expected 61222333.
The older version 7.7.5 works fine.
Is there a reason why the nuget package is not strongly named ?
And is there a solution for this ?
I am having number to udpate that i can not use with AsYouTypeFormtter.
Consider Case:
I am having phoneNumber that is half written 45454 and i am changing coutry code for this number than its format also should get changed.
but I can not load character array to AsYouTypeFormtter. So as to update country region in formatter, formatter needs to be constructed again and it start again from first character.
It should have a way to load character array or complete string to TypeFormatter and continue next char from there.
When depending on PhoneNumbers.dll through NuGet in a project producing a strong name signed assembly this exception is thrown each time PhoneNumbers.dll would be used:
System.IO.FileLoadException: Could not load file or assembly 'PhoneNumbers, Version=8.8.10.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044) File name: 'PhoneNumbers, Version=8.8.10.0, Culture=neutral, PublicKeyToken=null'
This can be fixed by strong name signing PhoneNumbers.dll see PR #51
Hello, our project in .NET 4.5 used the option (so we don't have to handle the security permissions ourselves)
< runtime >
< NetFx40_LegacySecurityPolicy enabled="true"/ >
< /runtime >
And when we tried to run
PhoneNumbers.PhoneNumberOfflineGeocoder.GetInstance().GetDescriptionForValidNumber
it fails with the exception
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Could you please tell us why this happened, do we need a set of permissions?
Thanks :)
Nicolas
Hi,
I'm trying to open the sln to browse code and getting failures straight away in VS 2015:
C:\Source\libphonenumber-csharp\csharp\PhoneNumbers\PhoneNumbers.csproj : error : The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format. C:\Source\libphonenumber-csharp\csharp\PhoneNumbers\PhoneNumbers.csproj
C:\Source\libphonenumber-csharp\csharp\PhoneNumbers.Test\PhoneNumbers.Test.csproj : error : The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format. C:\Source\libphonenumber-csharp\csharp\PhoneNumbers.Test\PhoneNumbers.Test.csproj
Looking at the csproj files, they are in a format that I am completely unfamiliar with and don't have any "Compile" items listed. Thinking this was the new 2017 file format, I opened the sln there and it also complained:
Unsupported
This version of Visual Studio is unable to open the following projects. The project types may not be installed or this version of Visual Studio may not support them.
For more information on enabling these project types or otherwise migrating your assets, please see the details in the "Migration Report" displayed after clicking OK.
- PhoneNumbers, "C:\Source\libphonenumber-csharp\csharp\PhoneNumbers\PhoneNumbers.csproj"
Non-functional changes required
Visual Studio will automatically make non-functional changes to the following projects in order to enable them to open in Visual Studio 2015, Visual Studio 2013, Visual Studio 2012, and Visual Studio 2010 SP1. Project behavior will not be impacted.
- PhoneNumbers, "C:\Source\libphonenumber-csharp\csharp\PhoneNumbers.sln"
I've looked at earlier versions of the csproj and it seems to have changed March 11 2017 and then March 13 says "Converted to 2017" - but it does not open in 2017.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.