How to Validate a City, State, or Province Name in Node.JS

Cloudmersive
2 min readSep 11, 2020

--

Your client’s personal information should always be a top priority, and verifying that information is key. Often, when working with addresses in shipping and billing, cities and areas such as states or provinces may have similar or the same names. To ensure that you are collecting the correct address information, the following Cloudmersive API will allow you to validate City and State/Province names instantly.

First, you will need to run this command to install the SDK:

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, you can run our function, AddressValidateCity:

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.AddressApi();var input = new CloudmersiveValidateApiClient.ValidateCityRequest(); // ValidateCityRequest | Input parse requestvar callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.addressValidateCity(input, callback);

If you only need to validate the State or Province name, you can instead call our function, AddressValidateState:

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.AddressApi();var input = new CloudmersiveValidateApiClient.ValidateStateRequest(); // ValidateStateRequest | Input parse requestvar callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.addressValidateState(input, callback);

With that, you will be able to confidently ship to or bill your clients without fear of a mistype or mix-up in their address. You can retrieve your personal API Key on the Cloudmersive website at no cost. This will give you access to up to 800 calls across our entire library of APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet