使用twilio验证电话号码

时间:2015-10-25 00:12:53

标签: twilio twilio-php twilio-click-to-call

我想实施电话号码验证,以检查电话号码是否存在。

我做了这个

Imports Twilio.Lookups

If Not File.Exists("list.txt") Then
         MsgBox("insert phone numbers to list.txt")

         Return
     Else
         Dim list() As String = File.ReadAllLines("list.txt")
         ListBox1.Items.AddRange(list)



     End If

     Dim accountSid As String = "AC862c52baff7d8ef72c9e4c04f828fa03"
     Dim authToken As String = "xxxxxxxxxxxx"
     Dim lookups As New LookupsClient(accountSid, authToken)
For Each str4 In ListBox1.Items
    Dim phoneNumber = lookups.GetPhoneNumber(str4, True)
    If ((((Not phoneNumber.Carrier Is Nothing) AndAlso (Not phoneNumber.Carrier.Name Is Nothing)) AndAlso ((Not phoneNumber.NationalFormat Is Nothing) AndAlso (Not phoneNumber.PhoneNumber Is Nothing))) AndAlso (Not phoneNumber.CountryCode Is Nothing)) Then
        Console.WriteLine(phoneNumber.Carrier.Name)
    ElseIf (Not phoneNumber.RestException Is Nothing) Then
        Console.WriteLine(phoneNumber.RestException.Message)
    Else
        Console.WriteLine("Phone number was correct, although the carrier who owns it was not found.")
    End If


Next

但这只会进行运营商查询,但不会检查实际的电话号码是否存在。

2 个答案:

答案 0 :(得分:1)

Twilio开发者传道者在这里。

验证电话号码存在的最佳方法是发送短信或拨打电话,为用户提供一个代码,然后他们需要将这些代码重新输入您的应用程序,以表明他们是通过该手机获得的。只需使用Twilio API的Lookups功能,即可告诉您电话号码是否为电话号码,而不是是否有人拥有它或将其与手机一起使用。

Twilio Blog上有一个很好的how to do phone verification with PHP示例。还有一个phone verification with Ruby on Rails的例子。希望他们可以帮助您构建解决方案。

答案 1 :(得分:0)

我建议您使用regular expressions并阅读this相关文章。