user3073180
user3073180

Reputation: 65

Validating phone number in Java using twilio

I want to verify if a phone number is valid and what is the type of phone number [cell/landline]. How can this be achieved in Java using twilio?

Thanks.

Upvotes: 1

Views: 838

Answers (1)

philnash
philnash

Reputation: 73029

Twilio developer evangelist here.

For this you can use the Lookup API. Take a look through the documentation on how to use the Lookup API in Java.

Here's a quick example though. You'll need to install the Java helper library, then try this code:

import com.twilio.sdk.LookupsClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.lookups.PhoneNumber;

public class Example {

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "{{ account_sid }}";
  public static final String AUTH_TOKEN = "{{ auth_token }}";

  public static void main(String[] args) throws TwilioRestException {
    LookupsClient client = new LookupsClient(ACCOUNT_SID, AUTH_TOKEN);

    PhoneNumber number = client.getPhoneNumber("+15108675309", true);

    System.out.println(number.getType());
    System.out.println(number.getCarrierName());
  }
}

Let me know if this helps at all.

Upvotes: 3

Related Questions