Reputation: 39
I want to implement phone number validation which checks whether phone number exist or does not exist.
I did this
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
but this only does carrier lookup, it does not check if the actual phone number exists.
Upvotes: 1
Views: 2458
Reputation: 73075
Twilio developer evangelist here.
The best way to validate the existence of a phone number is to send an SMS message or make a phone call providing the user with a code that they then need to enter back into your application to show that they got it on that phone. Just using the Lookups functionality of the Twilio API will tell you if the phone number is a phone number, but not whether anyone owns it or uses it with a phone.
There is a good example of how to do phone verification with PHP on the Twilio Blog. There is also an example of phone verification with Ruby on Rails. Hopefully they can help you build out your solution.
Upvotes: 2
Reputation: 485
I would suggest using regular expressions and reading this related article.
Upvotes: 0