๐ Phone Parser
A Dart library for parsing, validating, and formatting phone numbers โ always in sync with Googleโs libphonenumber.
Unlike traditional phone number libraries where you wait for maintainers to publish updates, phone_parser auto-syncs with Googleโs libphonenumber.
That means whenever Google ships a new release, your project gets the latest intelligence instantly โ no delays, no stale metadata, no headaches.
โจ Whether youโre building a shiny new Flutter app or running a Dart backend server, phone_parser is smart, reliable, and always up-to-date.
So you can focus on building while phone_parser takes care of keeping things current. ๐ก
๐ Why phone_parser?
Googleโs libphonenumber is fantastic, but:
- โ It isnโt natively available for all platforms.
- โ You often need channels or bindings to use it.
- โ Updates depend on maintainers.
โ
phone_parser solves this:
- Works across all Dart platforms (Flutter, backend, CLI).
- Ships with auto-synced metadata from Googleโs libphonenumber.
- A fork of
phone_numbers_parserwith seamless updates built-in.
โจ Features
- โ Validation โ Check if a number is valid, by type (mobile, fixed line, VoIP, etc.)
- โ Formatting โ Format numbers region-specifically
- โ Phone Ranges โ Expand or compare ranges of numbers
- โ Number Extraction โ Find phone numbers in plain text
- โ Eastern Arabic digits support
- โ Best-in-class metadata โ Always fresh from Googleโs libphonenumber
๐ Demo
Try it out: Live Demo
๐ฆ Installation
dependencies:
phone_parser: ^latest
๐ Usage
Start with the PhoneNumber class:
import 'package:phone_parser/phone_parser.dart';
void main() async {
// Load metadata before parsing numbers
await MetadataFinder.readMetadataJson("./");
final frPhone0 = PhoneNumber.parse('+33 655 5705 76');
// Parsing in different contexts
final frPhone1 = PhoneNumber.parse('0 655 5705 76', callerCountry: "FR");
final frPhone2 = PhoneNumber.parse('011 33 655-5705-76', callerCountry: "US");
final frPhone3 = PhoneNumber.parse('011 33 655 5705 76', destinationCountry: "FR");
final isAllEqual = frPhone0 == frPhone1 && frPhone0 == frPhone2 && frPhone0 == frPhone3;
print(frPhone1);
print('All representations equal: $isAllEqual');
// โ
Validation
print('valid: ${frPhone1.isValid()}');
print('valid mobile: ${frPhone1.isValid(type: PhoneNumberType.mobile)}');
print('valid fixed line: ${frPhone1.isValid(type: PhoneNumberType.fixedLine)}');
// โ
Extract numbers from text
final text = 'hey my number is: +33 939 876 218, or call me on +33 939 876 999';
final found = PhoneNumber.findPotentialPhoneNumbers(text);
print('Found: $found');
}
โ Validation
final valid = phone.validate();
final validMobile = phone.validate(type: PhoneNumberType.mobile);
final validFixed = phone.validate(type: PhoneNumberType.fixedLine);
๐จ Formatting
Region-specific formatting that respects local conventions:
final phoneNumber = PhoneNumber.parse('2025550119', destinationCountry: IsoCode.US);
print(phoneNumber.formatNsn()); // (202) 555-0119
๐ข Ranges
Work with phone numbers like numbers:
final first = PhoneNumber.parse('+33 655 5705 00');
final last = PhoneNumber.parse('+33 655 5705 03');
final range = PhoneNumber.getRange(first, last);
print('Count: ${range.count}');
print('Expanded: ${range.expandRange()}');
final one = PhoneNumber.parse('+33 655 5705 01');
final two = PhoneNumber.parse('+33 655 5705 02');
if (one.isAdjacentTo(two)) print('We are adjacent');
if (one.isSequentialTo(two)) print('$two comes after $one');
final three = two + 1;
print('Still a phone number: $three'); // +33 655 5705 03
๐ค Contributing
Contributions are welcome! ๐
If youโd like to improve phone_parser:
- Fork the repo
- Create a new branch:
git checkout -b feature/my-feature - Commit your changes:
git commit -m 'Add my feature' - Push to the branch:
git push origin feature/my-feature - Open a Pull Request ๐
๐ License
This project is licensed under the MIT License.
๐ก Summary:
- ๐ Works everywhere (Flutter, CLI, Server)
- โก Auto-syncs with Googleโs libphonenumber
- ๐ Reliable, consistent, always up-to-date
๐จโ๐ป Author
Libraries
- phone_parser
- Support for doing something awesome.
