問題描述
如何將手機號碼拆分為國家代碼、地區代碼和本地號碼?例如+919567123456 拆分后
How to split mobile number into country code, area code and local number? e.g +919567123456 after split
國家代碼 = 91
區號 = 9567
本地號碼 = 123456
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.
國家代碼相當簡單,只需使用 國家呼叫代碼 文章中的數據在 wikipedia 中并建立一個包含所有唯一國家代碼的表格.每個國家/地區都有一個唯一的前綴,這很容易.
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.
這篇關于如何將手機號碼拆分為國家代碼、地區代碼和本地號碼?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!