0

I'm trying to sanitize phone numbers in Android. Currently I'm using the well known libphonenumber library from Google, but I can't see any way of stripping withheld codes (and maybe others) from a phone number. I'm talking, in general, about those allowed codes (per carrier or country) that you can prepend to a phone number to affect to the call service (using special chars like '#', '*' or just with a fixed number).

There are many of those. E.g. in Europe you can type #31# before any phone number to hide your number to the call recipient. If I try to parse a phone number including such code with the library, it throws an exception:

String phone = "#31#666012345";

try {
    PhoneNumberUtil.getInstance().parse(phone, "ES");
} catch (NumberParseException e) {
    // will enter here
    e.printStackTrace();
}

Any ideas on how to do this? Thank you !

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
USB
  • 53
  • 1
  • 6
  • "Any ideas on how to do this?" -- come up with a list of codes and remove them from the string before passing the string to `PhoneNumberUtil`. – CommonsWare Nov 26 '14 at 17:08
  • Yep, that was my first thought, but the list is very extensive as it may vary per phone carrier or country, and they don't follow a standard format. So I was wondering whether anybody knows a library/API/service/code that can take care of that (pretty much as it's done with the country codes) – USB Nov 27 '14 at 08:43
  • Asking for off-site "library/API/service/code" is considered off-topic for Stack Overflow. – CommonsWare Nov 27 '14 at 11:54

0 Answers0