1

I'm new to android development. I am trying to make an SMS app. Everything works fine already except for phone number formatting. Say for example, I live in the Philippines and I got 2 different SMS from the same number.

First SMS address: +639123456789

Second SMS address: 09123456789

+639123456789 must equal to 09123456789

Or Swiss number +41446681800 must equal to 0446681800

Now how can I format either of these addresses that they will match. String manipulation will work but it's limited for Philippines only. I found this libphonenumber but I have no idea how to use it on my current project. Sorry for being noob. Any help would be much appreciated.

Community
  • 1
  • 1
Clyde Winux
  • 285
  • 1
  • 3
  • 12

2 Answers2

0

Here you can find an example for libphonenumber lib.

Using this library you can convert those numbers into international format, after you can match the numbers and if you want, you can get the country code too.

internationalFormatMobileNumber = phoneUtil.format(yourNumber, PhoneNumberFormat.INTERNATIONAL);
Anjula
  • 1,690
  • 23
  • 29
0

If you know the country for which you want to do it, you can use Google's open source library https://github.com/googlei18n/libphonenumber . Here is how you can format it:


             String numberStr = "8885551234"
            PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
            try {
              PhoneNumber numberProto = phoneUtil.parse(numberStr, "US");
              //Since you know the country you can format it as follows:
              System.out.println(phoneUtil.format(numberProto, PhoneNumberFormat.NATIONAL));
            } catch (NumberParseException e) {
              System.err.println("NumberParseException was thrown: " + e.toString());
            }