How to Validate a First Name in PHP

Cloudmersive
1 min readMar 30, 2020

Today we are going to demonstrate how to use an API to rapidly set up name validation with PHP.

We shall start out with our installation, handled with this command here:

composer require cloudmersive/cloudmersive_validate_api_client

Next comes our function, in this case nameValidateFirstName.

<?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\FirstNameValidationRequest(); // \Swagger\Client\Model\FirstNameValidationRequest | Validation request informationtry {$result = $apiInstance->nameValidateFirstName($input);print_r($result);} catch (Exception $e) {echo 'Exception when calling NameApi->nameValidateFirstName: ', $e->getMessage(), PHP_EOL;}?>

And that takes care of that. To test it out, simply input a name to be validated. This easy method applies to other functions in this same API client, allowing you to perform a myriad of tasks such as validating email addresses, parsing full names, determining time zones, and checking mailing addresses.

--

--

Cloudmersive

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