Google的公共Java、C++和Javascript庫用來解析,格式化,存儲和驗證國際電話號碼:libphonenumber

jopen 9年前發布 | 71K 次閱讀 常用工具包 libphonenumber

libphonenumber是Google的公共Java、C++和Javascript庫用來解析,格式化,存儲和驗證國際電話號碼。 其中Java版本優化用于運行在智能手機上,并且用在了 Android framework 4.0 (Ice Cream Sandwich)以上的版本中。

功能亮點:

  • Parsing/formatting/validating phone numbers for all countries/regions of the world.
  • getNumberType - gets the type of the number based on the number itself; able to distinguish Fixed-line, Mobile, Toll-free, Premium Rate, Shared Cost, VoIP and Personal Numbers (whenever feasible).
  • isNumberMatch - gets a confidence level on whether two numbers could be the same.
  • getExampleNumber/getExampleNumberByType - provides valid example numbers for all countries/regions, with the option of specifying which type of example phone number is needed.
  • isPossibleNumber - quickly guessing whether a number is a possible phonenumber by using only the length information, much faster than a full validation.
  • isValidNumber - full validation of a phone number for a region using length and prefix information.
  • AsYouTypeFormatter - formats phone numbers on-the-fly when users enter each digit.
  • findNumbers - finds numbers in text input.
  • PhoneNumberOfflineGeocoder - provides geographical information related to a phone number.
  • PhoneNumberToCarrierMapper - provides carrier information related to a phone number.
  • </ul>

    String swissNumberStr = "044 668 18 00"
    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
    try {
      PhoneNumber swissNumberProto = phoneUtil.parse(swissNumberStr, "CH");
    } catch (NumberParseException e) {
      System.err.println("NumberParseException was thrown: " + e.toString());
    }

    項目主頁:http://www.baiduhome.net/lib/view/home/1418785741652

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!