Comments (4)
After some digging those numbers appear to be from Inmarsat and South Sudan respectively. All numbers, in order to parse need to be either in E164 format (+870773924761, +211912378429), or have their region code provided. For South Sudan "SS", for Inmaset I can find reference to one but "GB" works.
from libphonenumber-csharp.
Hi Tom,
As I understand, the specified numbers are in E164 format.
So without specifying region code, it can be parsed.
But it throws an exception on my side.
Here is the code snippet, please advise if it needs any correction...
public static bool TryParse(string s, out Number number)
{
number = null;
//if (s == null || !s.All(char.IsDigit))
// return false;
s = "+" + s.Substring(2);
var phoneNumberUtil = PhoneNumberUtil.GetInstance();
if (phoneNumberUtil.IsPossibleNumber(s, null))
{
var phoneNumber = phoneNumberUtil.Parse(s, null);
if (phoneNumberUtil.IsValidNumber(phoneNumber))
{
string regionCode = phoneNumberUtil.GetRegionCodeForNumber(phoneNumber);
// +870773924761 Region Code = '001'
if (InternationalNumberManager.RegionCountryNameDictionary.TryGetValue(regionCode, out string region))
{
string desc;
// +211912378429 Exception
try
{
string cityState = PhoneNumberOfflineGeocoder.GetInstance().GetDescriptionForValidNumber(phoneNumber, Locale.English);
desc = ((cityState == region) ? cityState : cityState + ", " + region) + " (International)";
}
catch
{
desc = region + " (International)";
}
number = new InternationalNumber { Code = phoneNumber.CountryCode, Description = desc };
return true;
}
}
}
return false;
}
The input is like 00870773924761, 00211912378429, etc...
InternationalNumberManager.RegionCountryNameDictionary is Dictionary<string, string> type.
Thanks
from libphonenumber-csharp.
Copying your code above, of the few numbers I've tried nothing throws an exception. It returns false if the region code isn't in the dictionary. The first number returns a region code of "001" (quite the curious number you've selected), the second "SS", as long as both of these are in the dictionary both work without error and return true for me.
from libphonenumber-csharp.
Hi Tom,
Thanks for verifying the code and numbers.
Why there is an issue with 00211912378429 number.
The try/catch block is added for it specifically.
Thanks
from libphonenumber-csharp.
Related Issues (20)
- How to parse without getting exception for wrong format? HOT 10
- Country Code is added to NationalNumber in PhoneNumber Object if Number is too short HOT 1
- Could not load file or assembly 'System.IO.Compression HOT 6
- Document how changes in Google's base library are included or not HOT 2
- Strong named assemblies HOT 2
- Make metadata update and publish new version fully automatically HOT 1
- New Kazakhstan country code. HOT 1
- Could not interpret numbers after plus-sign when parsing +00000000000000 HOT 3
- Missing or invalid default region. HOT 2
- IsPossibleNumberForTypeWithReason returns valid mobile when IsValidNumber returns invalid HOT 1
- Valid US number is resulting in IsValid to false HOT 4
- Parsing phone number as valid when it starts with _ HOT 9
- GetNumberType always returns UNKNOWN HOT 2
- Breaking change in PhoneNumberUtil.Normalize HOT 2
- Enable nullable reference types
- American phone not correctly parsed? HOT 2
- Version 8.13.26 causes IndexOutOfRangeException HOT 3
- Vietnamese phone number does not validate HOT 1
- French mobile numbers with prefix "07" are not detected as mobile numbers HOT 2
- docs: codecov badge on README leads to old trunk branch "master" instead of the new "main" branch HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libphonenumber-csharp.