How to Validate Last Names in PHP

Cloudmersive
1 min readApr 27, 2023

--

When validating name entries in any application, the key is to distinguish between three distinct categories of names: valid & known names, valid & unknown names, and spam entry names (i.e., those containing special characters). You can easily validate name entries with that logic by implementing the free-to-use Last Name Validation API provided below in this article.

To take advantage of this API, you’ll first need to grab a free-tier API key from the Cloudmersive website. This will provide you with 800 free API calls per month and no commitments.

After that, you can run the following command to install the client SDK:

composer require cloudmersive/cloudmersive_validate_api_client

Then you can structure your API call using the ready-to-run PHP code examples provided below:

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');



$apiInstance = new Swagger\Client\Api\NameApi(


new GuzzleHttp\Client(),
$config
);
$input = new \Swagger\Client\Model\LastNameValidationRequest(); // \Swagger\Client\Model\LastNameValidationRequest | Validation request information

try {
$result = $apiInstance->nameValidateLastName($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling NameApi->nameValidateLastName: ', $e->getMessage(), PHP_EOL;
}
?>

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet