How to Validate a Name in Node.JS

Utilizing online submission and sign-up capabilities for your website can open your business to new clients and help create a user-friendly interface. Before, accepting user input, however, your systems should be equipped to check submissions such as name values, to ensure that the input is valid. The following APIs will allow you to check the full input names or, if preferred, first and last names separately.

Image for post
Image for post

Our first API will validate full name input as a string and return all applicable fields including the title, first name, middle name, last name, nickname, suffix, and display name of a user.

To use this or the APIs following it, our first step is to run this command to install the SDK:

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

If you prefer, you can also add this snippet to your package.json:

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

Then, we can call our function, NameValidateFullName:

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.NameApi();var input = new CloudmersiveValidateApiClient.FullNameValidationRequest(); // FullNameValidationRequest | Validation request informationvar callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.nameValidateFullName(input, callback);

Our next API will determine whether a first name input is valid. The SDK install steps should be completed as shown above; then, we can call our function, NameValidateFirstName:

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.NameApi();var input = new CloudmersiveValidateApiClient.FirstNameValidationRequest(); // FirstNameValidationRequest | Validation request informationvar callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.nameValidateFirstName(input, callback);

Finally, our last API will validate last name input. Once again, you can follow the install steps for our SDK above. After this, you can call our final function, NameValidateLastName:

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.NameApi();var input = new CloudmersiveValidateApiClient.LastNameValidationRequest(); // LastNameValidationRequest | Validation request informationvar callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.nameValidateLastName(input, callback);

With this, you can ensure your user input is always correct and can be stored appropriately in your databases. To run these APIs, you API Key can be found at the Cloudmersive website. This will give you access to 800 free calls across our library of APIs.

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud 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