giggsey/libphonenumber-example

Support empty country field when the number is prefixed with +

fdelapena opened this issue · 3 comments

libphonenumber can guess the country if the input number starts with a plus sign (+). This is a pretty useful feature from the library and nice to have shown. Here is a hackish demonstration by sending a null character (%00 urlencoded) to the form to circunvent the required country code:

http://giggsey.com/libphonenumber/?phonenumber=%2B50689999999&country=%00

Which will resolve properly the country code by itself.

How about I change the form so that it's not required, and if it's not populated, it'll use 'ZZ' (which means Unknown Region)?

It is an option, however it depends about how do you want to demonstrate the library. Unfortunately parse() it does not work without country definition with numbers starting without +, e.g. 0050689999999 (just because 00 is country specific), maybe explaining this fact or simply checking via javascript if the field has a leading + to enable the unknown option in the selection dropdown, or returning an explanation after the form submit when the missing country error appears.

Quite a bit late, but I've added some help text, and made the Country Code optional (matching what parse() actually accepts).

Thanks