๐Ÿ“ž Phone Parser

Pub Version License GitHub stars

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_parser with 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:

  1. Fork the repo
  2. Create a new branch: git checkout -b feature/my-feature
  3. Commit your changes: git commit -m 'Add my feature'
  4. Push to the branch: git push origin feature/my-feature
  5. 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

Sumit Kumar
Sumit Kumar

Libraries

phone_parser
Support for doing something awesome.