如何从规范化的电话号码中识别国家/地区? [英] How to identify a country from a normalized phone number?

查看:102
本文介绍了如何从规范化的电话号码中识别国家/地区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个国际电话列表和国家/地区电话代码列表. br> 我想从数字中识别国家/地区,但找不到快速,优雅的方法.

I have a list of international phone numbers and a List of Country calling codes.
I would like to identify the Country from the numbers but I can't find a fast and elegant way to do it.

有什么主意吗?我唯一得到的是进行硬编码的校验(例如,看第一个数字,看第二个数字:如果是X,则检查第三个数字.如果第二个数字是Y,则国家/地区是Foo",依此类推) ). 我在列表中使用PHP和DB(MySQL),但我认为任何伪代码都会有所帮助.

Any idea? The only I got is to have an hardcoded check (Eg. "look at the first number, look at the second number: if it's X then check for the third number. If the second number is Y then the Country is Foo", etc.). I'm using PHP and a DB (MySQL) for the lists, but I think that any pseudocode will help.

推荐答案

或者,您可以使用 Twilio查找之类的工具.

当您使用Lookup发出API请求时,总是返回CountryCode属性.

The CountryCode property is always returned when you make an API request with Lookup.

https://www.twilio.com/docs/api/lookups#lookups-instance-properties

[披露:我为Twilio工作]

这篇关于如何从规范化的电话号码中识别国家/地区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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