How to Validate a First Name in C# .NET Framework

Cloudmersive
2 min readMar 26, 2020

Validating names is a great way to weed out false user submissions as well as prevent a whole host of different problems that can crop up when names are incorrect. Don’t be afraid, though, we are not going to be dealing with international name databases or anything like that. Instead, we will be taking the simple approach, that of using an API to validate the names for us. Let’s dive in.

We must start by running this command in the console of package manager, which will begin installation of our client.

Install-Package Cloudmersive.APIClient.NET.Validate -Version 2.0.7

Now it’s time for the NameValidateFirstName function:

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.Validate.Api;using Cloudmersive.APIClient.NET.Validate.Client;using Cloudmersive.APIClient.NET.Validate.Model;namespace Example{public class NameValidateFirstNameExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new NameApi();var input = new FirstNameValidationRequest(); // FirstNameValidationRequest | Validation request informationtry{// Validate a first nameFirstNameValidationResponse result = apiInstance.NameValidateFirstName(input);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling NameApi.NameValidateFirstName: " + e.Message );}}}}

Now enter a name to test out and the API will send you back its judgment. It’s as simple as that!

--

--

Cloudmersive

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