How to Parse and Validate a Full Name in Node.JS

Name validation can really save you from a whole host of different headaches when dealing with customers and the public in general. It can stave off spam submissions with false names, help you address misspelled names on form submissions, and even save your customer service department from embarrassment. So, while this is obviously of great use, we need to know how to pair this usefulness with an easy implementation to save you from coding worries as well. We are going to do this today through use of an API.

To use our API, we first need to install its client through npm install:

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

From there, it’s simply a matter of calling our function with this code here:

var CloudmersiveValidateApiClient = require('cloudmersive-validate-api-client');var defaultClient = CloudmersiveValidateApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';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);

Now enter in a name and test it out. Let’s try it out on “Sir Jonathan Albus van Hoeg Jr” and we will be returned this result:

{
"Successful": true,
"ValidationResult_FirstName": "ValidFirstName",
"ValidationResult_LastName": "ValidUnknownLastName",
"Title": "Sir",
"FirstName": "Jonathan",
"MiddleName": "Albus",
"LastName": "van Hoeg",
"NickName": null,
"Suffix": "Jr",
"DisplayName": "Jonathan Albus van Hoeg"
}

--

--

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
Cloudmersive

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