Hello everybody,
i am using the libphonenumber library to change the format of phone
numbers. Unfortunately I'm facing a problem with German numbers and I
would like to change the behavior of the formatting.
The following lines are used to format a phone number:
PhoneNumber phoneNumber =
PhoneNumberUtil.getInstance().parse(unformattedValue, "DE");
value = phoneUtil.format(phoneNumber,
PhoneNumberFormat.INTERNATIONAL);
I get the following result:
unformattedValue="0172 7369456" -> value="+49 172 7369456"
unformattedValue="089 123456789" -> value="+49 89/123456789"
Now I would like to format the second number with a space instead of a
slash (+49 89 123456789).
I have tried to understand why libphonenumber is using the space for
mobil numbers and the slash for normal phone numbers. It seems that
the PhoneMetadata for Germany contains NumberFormat List that contains
7 entries. The first entry is taken because it matches the entered
number.
Looking at the PhoneMetadata regular expressions, there would be
probably more things to change.
How can I change the PhoneMetadata and use them with PhoneNumberUtil?
Why isn't there a way to access and to manipulate these Data?
Is there any documentation about the PhoneMetadata?
Often mobile and fixed-line formatting are different - the slash is
indicating that the prefix here is optional (an area code), but the
mobile numbers must be fully dialled.
A simpler way if you don't want to change the metadata or use format
by pattern is to do your own replace on the string afterwards to
change "/" and whatever other chars you don't want to a space...
We probably have to gather some use-cases to see what kind of
generalised solution would be appropriate. Is it just slashes you
don't want, or are there other symbols too?
2011/3/23 Boris Cassar <cassar...@googlemail.com>:
Hello Shaopeng,
my customer want to see the phone numbers displayed this way.
In Germany we use the slash if we write the numbers without the country prefix, i.e. 089/123456789 or a mobil number 0172/7369456. If there is the +49 prefix, it is not common to use the slash. But I don't think that this is a strict rule, there are plenty of special cases and possibilities.
In my case, I was very happy to find your library. I was able to present a quick solution to my customer (he came up with this issue a week before production delivery date). Thanks a lot. You saved me!
Boris