Dart phone number parser, based on libphonenumber and PhoneNumberKit.

Overview

Phone Number Parser

Dart library for parsing phone numbers. Inspired by Google's libphonenumber and PhoneNumberKit for ios.

The advantage of this lib instead of libphonenumber is that it instantly supports all platforms (no need for channeling).

Features

  • Find phone numbers in a text
  • Validate a phone number
  • Find the region of a phone number
  • Phone number parsing
  • Country list for display
  • Simple syntax
  • Supports easthern arabic digits
  • Uses best-in-class metadata from Google's libPhoneNumber project.

Usage

// creation
final frPhone = PhoneNumber.fromRaw('+33 655 5705 76');
final frPhone1 = PhoneNumber.fromIsoCode('fr', '655 5705 76');
final frPhone2 = PhoneNumber.fromDialCode('33', '655 5705 76');
final frPhone3 = PhoneNumber.fromIsoCode('fr', '0655 5705 76');
final international = '+33655570576';
final allInternationalEqual = international == frPhone.international &&
    international == frPhone1.international &&
    international == frPhone2.international &&
    international == frPhone3.international;
print(allInternationalEqual); // true

// extracting info
print(frPhone.dialCode); // 33
print(frPhone.isoCode); // fr
print(frPhone.validate(PhoneNumberType.fixedLine)); // false
print(frPhone.validate(PhoneNumberType.mobile)); // true
print(frPhone.validate(null)); // true

// changing the country
final esPhone = frPhone.copyWithIsoCode('ES');
print(esPhone.dialCode); // 34
print(esPhone.isoCode); // ES
print(esPhone.international); // '+34655570576'

// utils
final text = 'hey my phone number is: +33 939 876 218';
final found = PhoneNumberUtil.findPotentialPhoneNumbers(text);

// country list for display
final allCountries = countries; // contains name, isoCode, dialCode, leading digits, etc
 

Demo

The phone number input packages has a demo that uses this parser: https://cedvdb.github.io/phone_form_field/

Comments
  • Added PhoneNumberRange and numerical operators on PhoneNumber

    Added PhoneNumberRange and numerical operators on PhoneNumber

    I have the requirement to manage large no.s of phone number ranges.

    This PR includes a new class PhoneNumberRange which can store a contiguous range of phone numbers.

    New operators have been added to the PhoneNumber class to facilitate implementation of a ranges and numeric comparison of phone numbers.

    Small improvements to the description of exceptions to make locating the data that caused the problem easier.

    Added unit tests for PhoneNumberRange and the new operators in PhoneNumber.

    All unit tests are passing.

    opened by bsutton 13
  • provide a general PhoneNumberType

    provide a general PhoneNumberType

    there is no 'general' type in PhoneNumberType.So I can't use validate method with general type.The 'type = null' behavior is add all PhoneNumberType related pattern to patterns list for pattern matching. For number that only hit general pattern will return false by validate method.

    image

    image

    image

    opened by codenoobforreal 5
  • Using this library to format phone number

    Using this library to format phone number

    I wonder if it is possible to use this library to reverse its purpose i.e. to format a set of numbers into a phone number for a. given country:

    1234567890 -> (US) -> 123-456-7890

    opened by orestesgaolin 5
  • Enhanced the READ.ME ✅

    Enhanced the READ.ME ✅

    Hello 👋🏻

    In this PR you will find the following: ✅

    • Removed a redundant code line that was breaking the documentation format in pub.dev
    • Added a notice for the breaking changes in version 7.0.0
    • Enhanced the indentation of the code snippets

    I hope you like it.

    Thanks ❤ Moaz El-sawaf

    opened by moazelsawaf 3
  • migrate to fromRaw

    migrate to fromRaw

    The addition of the two parameters to fromRaw seems to be a more logical API. I've deprecated the other constructors as of now, before removing those in the future.

    steps required to remove others:

    • migrate tests
    • remove unnecessary methods and factories on phoneNumber and parser
    opened by cedvdb 3
  • Can you add format to international format

    Can you add format to international format

    Hello, Can you add formatting option to international format.

    I'm writing TextInputFormatter class for this librarry. Need to output national and international format

    Thanks in advance

    opened by Ilkhom-S 2
  • fromIso checks for wrong country code

    fromIso checks for wrong country code

    Hi,

    if I try to convert a US international call number to E164 using fromIso the country code is in my opinion not checked correctly in PhoneParser: Expected: PhoneNumber.fromIsoCode(IsoCode.US,"01149301234567").international == "+49301234567" Result: "+101149301234567" In contrast to the comment in line 74 phone_parser.dart the check does not check if any country code followed the international prefix but only checks if the given IsoCode prefix followed. ("if a country code did not immediately follow the international prefix") (E.g. parsing any non-german number with fromIsoCode(IsoCode.DE,"00....") also does not work).

    Or maybe I used the wrong function, but I would assume if I have a "national" international number I need to parse it with PhoneNumber.fromIsoCode, specififying the originating country?

    Cheers, Martin

    opened by mrclauss 2
  • With the 5.0.0 version, it's impossible to validate phone numbers for an arbitrary country

    With the 5.0.0 version, it's impossible to validate phone numbers for an arbitrary country

    Since 5.0.0, instead of specifying a country ISO code as string, this library requires using the generated enum. This is fine when a country is known at compilation time, but for multi-national apps it breaks the workflow. All I know is a string. Even if it were a enum, it would be a different enum, coming from a different library.

    Is there a way to use string ISO codes with this library?

    opened by Zverik 2
  • example number is considered invalid

    example number is considered invalid

    Hi, I noticed that a test number I have +44 7000000002 works in libphonenumber, but not with this library.

    I am not sure why, because it seems that you use libphonenumbers metadata...

    opened by EyMaddis 2
  • On-the-fly formatting

    On-the-fly formatting

    This library is great and imo superior to the other phone number libs out there. However, I can't figure out how to implement proper on-the-fly formatting with Flutter's TextInputFormatter.

    I tried to reference the TextInputFormatter from https://github.com/bottlepay/flutter_libphonenumber/blob/master/lib/src/input_formatter/input_formatter.dart

    however, this library's formatting doesn't really seem to work with phone numbers while they are being typed and still incomplete.

    opened by timcreatedit 1
  • PhoneNumber.fromRaw issue on valid E164 phone number

    PhoneNumber.fromRaw issue on valid E164 phone number

    Hi The static function PhoneNumber.fromRaw throw an exeception with a valid E164 phone number

    PhoneNumber.fromRaw('+33655570500')

    PhoneNumberException (PhoneNumberException(code: Code.invalidCountryCallingCode, description: countryCode 3 not found))

    opened by teddy-dubal 1
  • Wrong nsn result when trying to parse incomplete number of country with leading digits

    Wrong nsn result when trying to parse incomplete number of country with leading digits

    When trying to format incomplete numbers for "as-you-type" formatting, some countries produce wrong numbers by adding excess leading number at some stage. I were able to reproduce it only for countries with existing nationalPrefixTransformRule in metadata.

    Code to reproduce

    import 'package:phone_numbers_parser/phone_numbers_parser.dart';
    
    void main() {
      final fullBermudaNumber = PhoneNumber.parse('+14412957070');
      final incompleteBermudaNumber = PhoneNumber.parse('+14412957');
    
      print(fullBermudaNumber.nsn); // 4412957070 OK
      print(fullBermudaNumber.getFormattedNsn()); // 4412957070 OK
    
      print(incompleteBermudaNumber.nsn); // 4414412957 WRONG (4412957 expected)
      print(incompleteBermudaNumber.getFormattedNsn()); // 4414412957 WRONG (4412957 expected)
    
      final fullUSNumber = PhoneNumber.parse('+14056343023');
      final incompleteUSNumber = PhoneNumber.parse('+14056343');
    
      print(fullUSNumber.nsn); // 4056343023 OK
      print(fullUSNumber.getFormattedNsn()); // 405-634-3023 OK
    
      print(incompleteUSNumber.nsn); // OK
      print(incompleteUSNumber.getFormattedNsn()); // 405-634-3 OK
    }
    
    opened by cupofme 4
Owner
cedvdb
cedvdb
null 9 Dec 1, 2022
Args simple - A simple argument parser and handler, integrated with JSON and dart

args_simple A simple argument parser and handler, integrated with JSON and dart:

Graciliano Monteiro Passos 1 Jan 22, 2022
A Gura parser implementation for Dart

Gura Dart parser This repository contains the implementation of a Gura configuration format parser for Dart, written in pure Dart. (Compliant with spe

Zack Campbell 4 Aug 2, 2021
Parser tool is a real-time compiler and runtime engine for strongly typed PEG parsers

parser_tool Version 0.1.1 (BETA) Parser tool is a real-time compiler and runtime engine for strongly typed PEG parsers. Parser tool contains libraries

null 6 Jun 28, 2021
JSON API parser for Flutter

Flutter Japx - JSON:API Decoder/Encoder Lightweight [JSON:API][1] parser that flattens complex [JSON:API][1] structure and turns it into simple JSON a

Infinum 23 Dec 20, 2022
Future based HTTP client for the Dart and Flutter

Uno Future based HTTP client for the Dart and Flutter. Uno, inspired by Axios, bringing a simple and robust experience to the crossplatform apps in Fl

Flutterando 56 Dec 16, 2022
AFINN-based sentiment analysis for dart

Dart Sentiment is a dart module that uses the AFINN-165 wordlist and Emoji Sentiment Ranking to perform sentiment analysis on arbitrary blocks of input text.

Akash Lilhare 7 Nov 2, 2022
A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

Julien Scholz 10 Oct 26, 2022
A few handy Flutter tools, dead simple `UriRouter` for `Uri`-based navigator or `BuildTracker` to track widget rebuilds and what caused them to rebuild.

noob A few handy tools for Flutter apps. UriRouter Hooks Providers PointerIndicator BuildTracker PeriodicListenable UriRouter Dead simple Uri-based pa

null 6 Jan 18, 2022
Swagger/OpenAPI code generator based on Chopper and JsonAnnotation for Flutter

Code partially generated with chopper ?? Build dart types from Swagger/OpenAPI schemas SwaggerDartCodeGenerator is a code generator that looks for *.s

null 187 Jan 5, 2023
The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.

The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs. Inspired by SwiftGen. Motivation Using asset path str

FlutterGen 1.1k Jan 6, 2023
A code generation tool based on Database. :construction: developing :construction:

dbgen A code generation tool based on Database. Getting Started This project is a starting point for a Flutter application. A few resources to get you

尽管如此世界依然美丽 12 Jun 8, 2022
A high-performance, web standards-compliant rendering engine based on Flutter.

A high-performance, web standards-compliant rendering engine based on Flutter.

OpenKraken 4.8k Dec 30, 2022
A mobile map based application to help people everywhere around the world get help

Wonder This is a mobile application made by flutter. The application is called "Wonder" because it will help people everywhere around the world to get

Sara Nersisian 1 Dec 2, 2021
Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Google 905 Jan 2, 2023
Dart wrapper via dart:ffi for https://github.com/libusb/libusb

libusb Dart wrapper via dart:ffi for https://github.com/libusb/libusb Environment Windows(10) macOS Linux(Ubuntu 18.04 LTS) Usage Checkout example Fea

Woodemi Co., Ltd 28 Dec 20, 2022
Extensible Dart interpreter for Dart with full interop

dart_eval is an extensible interpreter for the Dart language, written in Dart. It's powered under the hood by the Dart analyzer, so it achieves 100% c

Ethan 169 Dec 28, 2022
The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

null 2 Oct 8, 2021
Library for help you make userbot or bot telegram and support tdlib telegram database and only support nodejs dart and google-apps-script

To-Do telegram client dart ✅️ support multi token ( bot / userbot ) ✅️ support bot and userbot ✅️ support telegram-bot-api local server ✅️ support tel

Azka Full Snack Developer:) 73 Jan 7, 2023