How to split mobile number into country code, area code and local number?

前端 未结 7 586
悲&欢浪女
悲&欢浪女 2020-12-03 10:33

How to split mobile number into country code, area code and local number? e.g +919567123456 after split

country code = 91

area code = 9567

local numb

7条回答
  •  盖世英雄少女心
    2020-12-03 11:04

    The answer very much depends on the country. There is no universal rule saying "this is country code, this is area code, this is local number". The only information that can be gained universally is the country number (and even that can be 1-4 digits long); then you need to consult the specific country's ruleset.

    For examples (like, "there are many different phone numbers in the given countries, but they all follow the same format"):

    • +420123456789 is a (bogus) number in Czech Republic (country code +420 ), and the rest IS the local number (some countries use an undivided addressing space, although you could infer a few bits of data from the first 1-4 digits of the local number (e.g. "+420800 are toll-free numbers")). So, the only useful way to parse this number is into two parts, +420 123456789.
    • +18005551234 is a (probably also bogus) number in the US; according to the North American numbering plan, +1 is country code, 800 is area code (toll-free numbers), 555 is exchange code and 1234 is local number. You can then parse the number into four parts, +1 800 555 1234.

提交回复
热议问题