How can I format a local mobile phone number to a international one?

1,317

Do I format the contact list phonenumber on the client side?

Or do I just send it and use a cloud function to somehow figure it out?

Client side - a good idea. Especially given the fact that just a local phone number is not enough. You also need to guess the country. And that's easier on the client side where you have more context. It's also better for performance.

And how do I do that?

Probably, that's what you're looking for:

  1. https://github.com/google/libphonenumber
  2. https://pub.dev/packages/phone_number#-example-tab-
Share:
1,317
anonymous-dev
Author by

anonymous-dev

Updated on December 19, 2022

Comments

  • anonymous-dev
    anonymous-dev over 1 year

    I am using the contact_service package for flutter to retrieve contacts from a device. But I noticed that when I look at the _contacts[index].phones it holds either mobile or other. I only take the contacts that have a mobiel phone number. But then when I look at the phonenumbers I see that they are all have a different format.

    +31XXXXXXXX
    +31 6 XXXXXXXX
    06-XXXXXXXX
    06 XXXXXXXX
    6 XXXXXXXX
    (045) XXXXXXXX
    045 XXXXXXXX
    

    Side Note: I am working on a android simulator with a google account

    I would prefer to have them all with a country code so that I can compare them with my firebase auth phonenumber. So my question is what do I do?

    Do I format the contact list phonenumber on the client side? Or do I just send it and use a cloud function to somehow figure it out? And how do I do that?