一个 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.