How to Validate a Last Name in PHP

Cloudmersive
1 min readMar 29, 2020

--

Name validation is great for a lot of reasons, but you don’t need me to tell you why. Instead, you need a way to get it done quickly, so let’s get straight to it.

Start with installation via the command line of composer:

composer require cloudmersive/cloudmersive_validate_api_client

Proceed to calling our function with this code:

<?phprequire_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');$apiInstance = new Swagger\Client\Api\NameApi(// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.// This is optional, `GuzzleHttp\Client` will be used as default.new GuzzleHttp\Client(),$config);$input = new \Swagger\Client\Model\LastNameValidationRequest(); // \Swagger\Client\Model\LastNameValidationRequest | Validation request informationtry {$result = $apiInstance->nameValidateLastName($input);print_r($result);} catch (Exception $e) {echo 'Exception when calling NameApi->nameValidateLastName: ', $e->getMessage(), PHP_EOL;}?>

And you’re already done. Input a last name and try it out! For more like this, check out the rest of what our validate API has to offer, including IP geolocation and email validation.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet