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

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.

Image for post
Image for post

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.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store