Validate a phone number

Phone number validation##

By asking your customer to provide a phone number — and then validating the legitimacy of that number — you minimize fraud and ensure that you can easily contact that customer in the future.

  • Enable this functionality in your application or portal to ensure your database is keeping only valid phone numbers for your users.
  • Apply phone number check for user the registrations.
  • Filter your database for invalid numbers and minimise cost for messaging campaigns.

Additionally, by using Number Validation you also distinguish mobile from landline numbers and ensure that you only send text messages to mobile phone numbers.

❗️

Requests to Number Validation API are not free.

See the API reference for more information.

Using phone number validation and lookup, you can reduce costs, build a stronger customer database and acquire a secure robust way to cross check user data input.

Regarding bulk messaging, you can validate, retrieve the international format and calculate the cost for sending SMS or phone calls to a phone number.

In this guide, we will validate the number +306932XXXXXX and get information on whether the number is ported to another network.

SAMPLE CODE

curl --request POST \
  --url https://connect.routee.net/numbervalidator \
  --header 'authorization: Bearer 9317b742-7e05-4202-ac2f-4074ab9a2ba1' \
  --header 'content-type: application/json' \
  --data '{"getPorted":"true","to":"+306932XXXXXX","host":"www.testdomain.com"}'
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"getPorted\":\"true\",\"to\":\"+306932XXXXXX\"}");
Request request = new Request.Builder()
  .url("https://connect.routee.net/numbervalidator")
  .post(body)
  .addHeader("authorization", "Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4")
  .addHeader("content-type", "application/json")
  .build();

Response response = client.newCall(request).execute();
var client = new RestClient("https://connect.routee.net/numbervalidator");
var request = new RestRequest(Method.POST);

request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4");
request.AddParameter("application/json", "\"getPorted\":\"true\",\"to\":\"+306932XXXXXX\"}", 
                     ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://connect.routee.net/numbervalidator",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "\"getPorted\":\"true\",\"to\":\"+306932XXXXXX\"}",
  CURLOPT_HTTPHEADER => array(
    "authorization: Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
import http.client

conn = http.client.HTTPSConnection("connect.routee.net")

payload = "{\n\"to\":\"+30697xxxxxxx\",\n\"getPorted\":\"true\"\n}"

headers = {
    'authorization': "Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4",
    'content-type': "application/json"
    }

conn.request("POST", "/numbervalidator", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'uri'
require 'net/http'

url = URI("https://connect.routee.net/numbervalidator")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["authorization"] = 'Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4'
request["content-type"] = 'application/json'
request.body = "\"getPorted\":\"true\",\"to\":\"+306932XXXXXX\"}"

response = http.request(request)
puts response.read_body
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://connect.routee.net/numbervalidator",
  "method": "POST",
  "headers": {
    "authorization": "Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4",
    "content-type": "application/json"
  },
  "processData": false,
  "data": "\"getPorted\":\"true\",\"to\":\"+306932XXXXXX\"}"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"authorization": @"Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4",
                           @"content-type": @"application/json" };
NSDictionary *parameters = @{  @"getPorted":@"true",@"to":@"+306932XXXXXX" };

NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://connect.routee.net/numbervalidator"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

RESPONSE

{  
   "to":"+306932XXXXXX",
   "createdAt":"2017-01-24T09:22:11.627Z",
   "getPorted":true,
   "numberValidatorId":"b2bff937-15eb-473f-b5bc-ba377acf03ba",
   "details":{  
      "type":"mobile",
      "ported":true,
      "network":"Cosmote (OTE)",
      "networkCode":"20201",
      "countryCode":"GRC",
      "countryPrefix":"30"
   },
   "formats":{  
      "international":"+30 693 2XX XXXX",
      "national":"693 2XX XXXX",
      "rfc3966":"tel:+30-693-2XX-XXXX"
   },
  "geo": {
        "host": "www.testdomain.com",
        "country": "Netherlands",
        "countryISO2Code": "NL",
        "countryISO3Code": "NLD",
        "continent": "EU"
    },
   "applicationName":"default",
   "valid":true
}

By parsing this JSON response, you can use the pre-formatted number to add it to your database and get information regarding the subscriber's current network.

Easy and simple!

To get more information check out our Resource Reference