Parse and Validate a Name in Swift

2 min readJun 1, 2021


If you allow users to submit contact information via online form submissions, there is a margin of error that comes along with the convenience. Invalid name values can throw a huge wrench in your customer transactions, causing order mix-ups, botched communications, and more. In an attempt to avoid these situations, I will be demonstrating how you can use an API in Swift to instantly parse and validate a full name string.

To call the validation function, you simply need to input your request string and API key into the following code:

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
var semaphore = DispatchSemaphore (value: 0)let parameters = "{\n \"FullNameString\": \"<string>\"\n}"
let postData = .utf8)
var request = URLRequest(url: URL(string: "")!,timeoutInterval: Double.infinity)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("YOUR-API-KEY-HERE", forHTTPHeaderField: "Apikey")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
print(String(data: data, encoding: .utf8)!)

This quick operation will parse the name, return its components, and inform you if it’s valid or invalid. To retrieve your API key, head to the Cloudmersive website to register for a free account; this provides access to 800 monthly calls across any of our APIs.




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