How to Validate a Phone Number in Node.JS

2 min readSep 21, 2020

Maintaining the accurate contact information and phone numbers for your clients and associates will help keep your business running smoothly and efficiently. When using online forms or other input such as emails to gather this information, however, you can run the risk of collecting incorrect data. The following API will help you validate all input phone numbers to check for correct syntax, country information, and different formats including international and E164.

Our first step for this API is to install our client:

npm install cloudmersive-validate-api-client --save

Or, you can add this snippet to your package.json:

"dependencies": {
"cloudmersive-validate-api-client": "^1.2.4"

Then we can call our function, PhoneNumberSyntaxOnly:

var CloudmersiveValidateApiClient = require('cloudmersive-validate-api-client');
var defaultClient = CloudmersiveValidateApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveValidateApiClient.PhoneNumberApi();var value = new CloudmersiveValidateApiClient.PhoneNumberValidateRequest(); // PhoneNumberValidateRequest | Phone number to validate in a PhoneNumberValidateRequest object. Try a phone number such as \"1.800.463.3339\", and either leave DefaultCountryCode blank or use \"US\".var callback = function(error, data, response) {
if (error) {
} else {
console.log('API called successfully. Returned data: ' + data);
apiInstance.phoneNumberSyntaxOnly(value, callback);

With this, you can easily maintain accurate phone information for all your connections. To retrieve your personal API Key, you can visit the Cloudmersive website. This will give you access to 800 free calls per month across our library of APIs.




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.