phone_numbers_parser 7.0.0+1 icon indicating copy to clipboard operation
phone_numbers_parser: ^7.0.0+1 copied to clipboard

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

Phone Numbers 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
  • A light parser for size aware applications
  • Formatter
  • Phone ranges
  • Supports eastern arabic digits
  • Uses best-in-class metadata from Google's libPhoneNumber project.

Usage #

Use the class PhoneNumber as a starting point

// raw parsing
PhoneNumber.fromRaw('655 5705 76', )

import 'package:phone_numbers_parser/phone_numbers_parser.dart';

void main(List

// validation final valid = frPhone1.isValid(); final validMobile = frPhone1.isValid(type: PhoneNumberType.mobile); final validFixed = frPhone1.isValid(type: PhoneNumberType.fixedLine); print('valid: $valid'); // true print('valid mobile: $validMobile'); // true print('valid fixed line: $validFixed'); // false

// utils final text = 'hey my phone number is: +33 939 876 218, but you can call me on +33 939 876 999 too'; final found = PhoneNumber.findPotentialPhoneNumbers(text); print('found: $found');


# validation

final valid = frPhone1.validate(); final validMobile = frPhone1.validate(type: PhoneNumberType.mobile); final validFixed = frPhone1.validate(type: PhoneNumberType.fixedLine); print('valid: $valid'); // true print('valid mobile: $validMobile'); // true print('valid fixed line: $validFixed'); // false


### Formatting

Formatting is region specific, so the formats will vary by iso code to accommodate
for local formats.

final phoneNumber = PhoneNumber.parse('2025550119', destinationCountry: IsoCode.US); final formattedNsn = phoneNumber.getFormattedNsn(); print('formatted: $formattedNsn'); // 202-555-0119/ 202-555-0119


### Range 

print('Ranges:'); 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('Expand: ${range.expandRange().join(',')}');

if (first > last) { print("this shouldn't be."); }

final one = PhoneNumber.parse('+33 655 5705 01'); final two = PhoneNumber.parse('+33 655 5705 02');

if (one.isAdjacentTo(two)) { print('We are together'); } if (one.isSequentialTo(two)) { print('$two comes after $one'); }

/// treat the phone no. like an int final three = two + 1; print('Its still a phone No. $three'); two - 1 == one; final another = one + 2; print('$another == $three');




93
likes
140
pub points
94%
popularity

Publisher

unverified uploader

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

Homepage

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

dart_countries, meta, phone_number_metadata

More

Packages that depend on phone_numbers_parser