How to Parse and Validate a Full Name using Java

Cloudmersive
2 min readSep 22, 2022

When we (or client-side application users) enter names into form fields, we typically do so either as a continuous string (i.e., “Jonathan Doe the Second”) or through individual entries (i.e., “Jonathan” + “Doe” + “The Second”). While the former option is a bit more fluid, it in turn makes validating the data entry slightly more complicated. Thankfully, with the help of our Full Name Validation API, you can easily parse & validate full names through a single entry string with very little fuss. This API will structure the parsed information into its individual parts, accommodating titles, middle names, nicknames, suffixes, and more. The below example response body shows the full list of possible response values:

{
"Successful": true,
"ValidationResult_FirstName": "string",
"ValidationResult_LastName": "string",
"Title": "string",
"FirstName": "string",
"MiddleName": "string",
"LastName": "string",
"NickName": "string",
"Suffix": "string",
"DisplayName": "string"
}

The best part? You can use this API completely free. All you need to do is register a free account on our website, which will supply a free-tier API key (good for 800 API calls per month — perfect for small-scale projects/startups). Once you have that, just follow instructions below in this article to install the API client & structure your API call in Java, and you’re good to go.

We can begin the client installation process by first adding a reference to the pom.xml repository:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

And we can wrap up installation by adding another reference to the pom.xml dependency:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>

Now we can turn our focus over to the controller and include the imports at the top of our file:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.NameApi;

Finally, we can call the function. We can authenticate our API key in the 4th line (where shown by the comments):

ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
NameApi apiInstance = new NameApi();
FullNameValidationRequest input = new FullNameValidationRequest(); // FullNameValidationRequest | Validation request information
try {
FullNameValidationResponse result = apiInstance.nameValidateFullName(input);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling NameApi#nameValidateFullName");
e.printStackTrace();
}

When we pass through our validation request information, we’ll want to make sure it’s formatted like so:

{
"FullNameString": "string"
}

--

--

Cloudmersive

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