Bulk Validate Phone Numbers Format for WhatsApp

Today you will learn how to use the Wassenger’s Number validator with our API which allows you to validate if a list of numbers is using the E164 format.

Wassenger
6 min readNov 5, 2024

--

Imagine having a tool that instantly checks if phone numbers are correctly formatted, saving you time and effort while reducing the chances of failed communications. Whether you’re managing a small contact list or a large database, accurate phone numbers are crucial for reaching your customers effectively.

That’s where the Wassenger Number Validator comes in as a powerful solution for ensuring every phone number you handle is in the correct E164 format. With the ability to validate up to 500 numbers per API request, this feature is ideal for businesses looking to streamline their communications. And the best part? There are no usage limits and no extra costs, so you can validate numbers freely without impacting your budget.

🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

Requirements

API endpoint

In this tutorial we will use the following API endpoint:

Prepare the request

Target API URL

https://api.wassenger.com/v1/numbers/validate

Required HTTPS headers

Content-Type: application/json
Token: $API-TOKEN

Request body in JSON format

{
"country": "US",
"numbers": [
{
"phone": "202-456-1414"
},
{
"phone": "+1 202 456 1414"
},
{
"phone": "1 415 (858-6273)"
}
]
}

Explore how to use the code in your browser without installing any software.

Validate numbers using the API

# Examples requires to have installed requests Python package.
# Install it by running: pip install requests

import requests

url = "https://api.wassenger.com/v1/numbers/validate"

payload = {
"country": "US",
"numbers": [{ "phone": "202-456-1414" }, { "phone": "+1 202 456 1414" }, { "phone": "1 415 (858-6273)" }]
}
headers = {
"Content-Type": "application/json",
"Token": "ENTER API KEY HERE"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.wassenger.com/v1/numbers/validate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'country' => 'US',
'numbers' => [
[
'phone' => '202-456-1414'
],
[
'phone' => '+1 202 456 1414'
],
[
'phone' => '1 415 (858-6273)'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Token: ENTER API KEY HERE"
],
]);

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

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
// Examples requires to have installed pecl_http package, a simple and elegant HTTP client for PHP.
// Install it by running: pecl install pecl_http
// More information: https://mdref.m6w6.name/http

<?php

$client = new http\Client;
$request = new http\Client\Request;

$body = new http\Message\Body;
$body->append(json_encode([
'country' => 'US',
'numbers' => [
[
'phone' => '202-456-1414'
],
[
'phone' => '+1 202 456 1414'
],
[
'phone' => '1 415 (858-6273)'
]
]
]));
$request->setRequestUrl('https://api.wassenger.com/v1/numbers/validate');
$request->setRequestMethod('POST');
$request->setBody($body);

$request->setHeaders([
'Content-Type' => 'application/json',
'Token' => 'ENTER API KEY HERE'
]);

$client->enqueue($request)->send();
$response = $client->getResponse();

echo $response->getBody();
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.wassenger.com/v1/numbers/validate"

payload := strings.NewReader("{\"country\":\"US\",\"numbers\":[{\"phone\":\"202-456-1414\"},{\"phone\":\"+1 202 456 1414\"},{\"phone\":\"1 415 (858-6273)\"}]}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Content-Type", "application/json")
req.Header.Add("Token", "ENTER API KEY HERE")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(res)
fmt.Println(string(body))

}
// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp

var client = new RestClient("https://api.wassenger.com/v1/numbers/validate");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "ENTER API KEY HERE");
request.AddParameter("application/json", "{\"country\":\"US\",\"numbers\":[{\"phone\":\"202-456-1414\"},{\"phone\":\"+1 202 456 1414\"},{\"phone\":\"1 415 (858-6273)\"}]}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
// This code uses the built-in HttpClient package in the .NET framework.
// Documentation: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-6.0

using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://api.wassenger.com/v1/numbers/validate"),
Headers =
{
{ "Token", "ENTER API KEY HERE" },
},
Content = new StringContent("{\"country\":\"US\",\"numbers\":[{\"phone\":\"202-456-1414\"},{\"phone\":\"+1 202 456 1414\"},{\"phone\":\"1 415 (858-6273)\"}]}")
{
Headers =
{
ContentType = new MediaTypeHeaderValue("application/json")
}
}
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}
require 'uri'
require 'net/http'

url = URI("https://api.wassenger.com/v1/numbers/validate")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request["Token"] = 'ENTER API KEY HERE'
request.body = "{\"country\":\"US\",\"numbers\":[{\"phone\":\"202-456-1414\"},{\"phone\":\"+1 202 456 1414\"},{\"phone\":\"1 415 (858-6273)\"}]}"

response = http.request(request)
puts response.read_body
// This code requires you to have installed Unirest package.
// Documentation: https://kong.github.io/unirest-java/#requests
// Installation: http://kong.github.io/unirest-java/

HttpResponse<String> response = Unirest.post("https://api.wassenger.com/v1/numbers/validate")
.header("Content-Type", "application/json")
.header("Token", "ENTER API KEY HERE")
.body("{\"country\":\"US\",\"numbers\":[{\"phone\":\"202-456-1414\"},{\"phone\":\"+1 202 456 1414\"},{\"phone\":\"1 415 (858-6273)\"}]}")
.asString();
$headers=@{}
$headers.Add("Content-Type", "application/json")
$headers.Add("Token", "ENTER API KEY HERE")
$response = Invoke-WebRequest -Uri 'https://api.wassenger.com/v1/numbers/validate' -Method POST -Headers $headers -ContentType 'application/json' -Body '{"country":"US","numbers":[{"phone":"202-456-1414"},{"phone":"+1 202 456 1414"},{"phone":"1 415 (858-6273)"}]}'

🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

Live API testing

You can live-test and play with the API directly from your browser.

Once you are done testing, get the auto-generated code example in your preferred programming language and you will be ready to go.

Try our API-Live tester now

🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and get started in minutes!

FAQ

How can I validate phone numbers?

We provide the Number validator API endpoint that allows you to validate the E164 format up to 500 phone numbers per API request. This API endpoint has no limit and can be called at no additional cost.

Please note this validation only validates whether the given phone number format is valid or not, but it will not validate whether it’s linked or not to an existing WhatsApp account.

For WhatsApp numbers existing validation please check the article below.

How can I validate if a phone number exists in WhatsApp?

You can validate whether a given phone number exists in WhatsApp or not, and therefore can receive messages in WhatsApp, by using the Number exists API endpoint.

Please note you must have at least one WhatsApp number connected to the platform to perform the validation.

How to validate if a phone number can receive WhatsApp messages?

You can validate if a given phone number is linked to a WhatsApp account and can receive messages.

The API provides an endpoint that can validate whether a given phone number exists in WhatsApp or not.

The only requirement is to have at least one WhatsApp number connected to the platform in your current account.

For more details, please check out the API endpoint documentation here.

WhatsApp number checks are limited per plan

Before you check if a phone number exists on WhatsApp, you can also validate and normalize the format of a list of phone numbers by using the numbers validator API endpoint. This endpoint only validates the correct E164 format, but it does not check whether the phone number effectively exists on WhatsApp or not.

Looking for more answers? Check out the extended FAQs.

Further useful resources

API Documentation 🖥️

For more details about the endpoint API, please check the documentation where you will find all the details about the accepted request params, possible success or error responses and ready-to-use code examples in multiple programming languages:

https://app.wassenger.com/docs/#tag/Numbers/operation/validateNumbers

--

--

Wassenger
Wassenger

Written by Wassenger

WhatsApp API + Team Chat + CRM + AI Assistant Solution for smart Businesses and Teams. Automate and work more productively with your clients on WhatsApp!

No responses yet