如何将手机号码分成国家代码,区号和本地号码? [英] How to split mobile number into country code, area code and local number?

查看:894
本文介绍了如何将手机号码分成国家代码,区号和本地号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将手机号码分成国家代码,区号和本地号码?
例如+919567123456分割后

国家代码= 91

区号= 9567



本地号码= 123456

解决方案

简单的算法,你需要使用填写每个国家的规则数据表 - 因为每个国家的电话号码分隔不同。



国家代码是相当容易的,只是使用数据来自维基百科的国家调用代码文章,并构建一个包含所有唯一国家/地区代码的表格。每个国家都有一个独特的前缀,所以这很容易。



但是,您需要查看您想要支持的每个国家/地区的规则,并提取区号使用每个国家的规则。


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 number = 123456

解决方案

It's not possible to parse phone numbers with a simple algorithm, you need to use data tables populated with each country's rules - because each country delimits their phone numbers differently.

The country code is fairly easy, just use the data from from the Country calling codes article in wikipedia and build a table of all the unique country codes. Each country has a unique prefix, so that's easy.

But then you need to look up the rules for every country you want to support and extract the area code(s) using the rules for each country.

这篇关于如何将手机号码分成国家代码,区号和本地号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆