Extract code country from phone number [libphonenumber]

前端 未结 7 1786
情深已故
情深已故 2020-11-27 13:21

I have a string like this : +33123456789 (french phone number). I want to extract the country code (+33) without knowing the country. For example, it should work if i have a

7条回答
  •  温柔的废话
    2020-11-27 13:51

    Here's a an answer how to find country calling code without using third-party libraries (as real developer does):

    Get list of all available country codes, Wikipedia can help here: https://en.wikipedia.org/wiki/List_of_country_calling_codes

    Parse data in a tree structure where each digit is a branch.

    Traverse your tree digit by digit until you are at the last branch - that's your country code.

提交回复
热议问题