AsYouTypeFormatter can't parse phone number without country code

100 views
Skip to first unread message

Alex S

unread,
Nov 21, 2024, 12:12:24 PM11/21/24
to libphonenumber-discuss
I'm trying to parse a number like +49160430XXXX. 
User already selected country code +49 in separate UI, so it needs only enter phone number: 160430XXXX. And it's not parsed. 
But if I try to parse 0160430XXXX (I hope it's national format) then it's parsed well.

Is it possible to make some configuration of AsYouTypeFormatter to parse number without initial 0?

Thank you,
Alex

Kavitha Keshava (xWF)

unread,
Nov 22, 2024, 12:57:39 AM11/22/24
to libphonenum...@googlegroups.com
Hi,

Thank you for using libphonenumber!

In Germany, national prefix '0' is mandatory to call within the country. So, it uses the below format to get the AYTF. uses https://github.com/google/libphonenumber/blob/a8e4057fb5655b91ce08c28955b929bf956cfcbb/resources/PhoneNumberMetadata.xml#L9050

If in a country national prefix is optional for eg. India then we set nationalPrefixOptionalWhenFormatting="true". So, AYTF will work here with and without the national prefix.

--
You received this message because you are subscribed to the Google Groups "libphonenumber-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libphonenumber-di...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/libphonenumber-discuss/e6381007-73ed-49a5-830e-5474c89dc657n%40googlegroups.com.

Lara Scheidegger

unread,
Nov 26, 2024, 1:34:05 AM11/26/24
to libphonenum...@googlegroups.com
An idea: It might work to input "+49" yourself, and then manually trim from the output each time, since you don't want to display the +49?

This might get tricky if you use any of the "remember position" functionality since you'd have to update that too, otherwise could work.

Reply all
Reply to author
Forward
0 new messages