一個 Dart 套件,使用 Google 的 libphonenumber 庫實現國際電話號碼處理。它提供強大的功能,用於解析、驗證、格式化以及確定全球格式下電話號碼的地區。適用於需要在不同地區進行準確電話號碼處理的應用程式,支援所有主要平台,包括行動裝置、網頁和桌面端。此套件確保使用者輸入驗證與顯示的一致性和正確性,減少國際通訊工作流程中的錯誤。
適用情境
驗證國際電話號碼
按地區格式化電話號碼
解析電話號碼元數據
從號碼中檢測國家
支援多區域使用者輸入
主要特色
基於 Google 的 libphonenumber
跨平台支援
全面驗證
地區特定格式化
自動數字類型檢測
適合對象
全球應用,帶用戶註冊
電信或訊息應用
國際表單輸入
需要精確數字解析的應用程式
需要可靠電話號碼邏輯的開發人員
使用建議
需要小心處理地區代碼
可能稍微增加應用大小
依賴原生程式碼以實現完整功能
僅限libphonenumber支援的國家
對無效輸入需要適當的錯誤處理
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
Dart LibPhoneNumber
A Dart package for working with international phone numbers based on Google's libphonenumber implementation. It parses, formats, and validates numbers without relying on native dependencies.
✨ Features
✅ Parse, format, and validate phone numbers [parse(), format(), isValidNumber()]
➝ Convert raw phone numbers into structured objects, apply different formats, and check validity.
✅ Identify phone number types [getNumberType()]
➝ Distinguishes between Fixed-line, Mobile, Toll-free, Premium Rate, VoIP, etc.
✅ Match and compare phone numbers [isNumberMatch()]
➝ Determines whether two numbers are the same or similar.
✅ Generate example phone numbers [getExampleNumber()]
➝ Provides valid phone number examples for various countries/regions.
✅ Perform quick validation [isPossibleNumber()]
➝ Checks if a number has a valid length without requiring region-specific details.
✅ Validate phone numbers for a specific region [isValidNumberForRegion()]
➝ Ensures a phone number is valid in the given country based on length and prefix rules.
✅ Format phone numbers as-you-type [getAsYouTypeFormatter()]
➝ Dynamically formats phone numbers as users enter each digit.
✅ Extract phone numbers from text [findNumbers()]
➝ Detects phone numbers within a block of text (e.g., 'Call me on 0241234567').
✅ Geocode phone numbers [getDescriptionForNumber()]
➝ Retrieves geographical information related to a phone number (e.g., 'Zurich' for a Swiss number).
✅ Retrieve carrier information [getNameForNumber()]
➝ Identifies the telecom provider associated with a number (e.g., 'AT&T', 'Vodafone').
✅ Find associated timezones [getTimeZonesForNumber()]
➝ Returns timezone(s) linked to a phone number (e.g., 'America/New_York').
🚀 Quick Start
📌 Installation
Add dlibphonenumber to your pubspec.yaml:
dependencies:dlibphonenumber:^1.1.35#replace with the current version number.