简体   繁体   English

为什么不存在电话号码数据类型/库

[英]Why doesn't a phone number datatype/library exist

Just wondering if anyone is aware of any low level phone number storage constructs for C#. 只是想知道是否有人知道C#的任何低级电话号码存储结构。 I have been surprised to find that all of my searches have proved fruitless for such a library. 我惊讶地发现,对于这样一个图书馆,我所有的搜索都被证明是徒劳的。

Essentially I am hoping for something that can take a string phone number input (in all its varied goodness) and both validate and segment the given string into its various sections (IE: country code, area code, number) along with providing a common format to store this data. 从本质上讲,我希望可以采用字符串电话号码输入(以其各种优点),并且可以将给定的字符串验证并分段成各个部分(即:国家/地区代码,区号,数字),并提供一种通用格式存储此数据。

Does any such library exist? 是否存在这样的库? If not, any idea why something like this hasn't been attempted? 如果没有,为什么不尝试这样的事情? (Is it really that hard a problem?) (问题真的那么难吗?)

I think that the main reason is that between people themselves there seems to be no real standard way of writing the phone number. 我认为主要原因是人与人之间似乎没有写电话号码的真正标准方法。 For instance, people living on small islands tend to not have regional codes and there is no need for the country code when calling residents of the same island. 例如,居住在小岛上的人们往往没有区域代码,致电同一个岛上的居民时不需要国家代码。

This changes when you move to larger places. 当您移至更大的地方时,情况会发生变化。 Also, I have seen certain numbers written as (XXXX)XXXXX or XXXXX-XXXXX or XXXXXXXXXX . 另外,我看到某些数字写为(XXXX)XXXXXXXXXX-XXXXXXXXXXXXXXX

The standard way of dealing with this seems to be with regular expressions. 处理此问题的标准方法似乎是使用正则表达式。 The developer usually takes a few possible input formats and uses regular expressions to validate and transform the format of the number. 开发人员通常采用几种可能的输入格式,并使用正则表达式来验证和转换数字格式。

So it turns out there is actually a pretty awesome library available after all. 事实证明,实际上毕竟有一个很棒的库。

Original Java version: http://code.google.com/p/libphonenumber/ 原始Java版本: http//code.google.com/p/libphonenumber/

C# version: https://bitbucket.org/pmezard/libphonenumber-csharp/wiki/Home C#版本: https//bitbucket.org/pmezard/libphonenumber-csharp/wiki/Home

Me discussing the library on my blog . 我在博客上讨论图书馆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM