How to validate a Code Identifier in PHP

Cloudmersive
2 min readMar 31, 2020

--

I’m going to go out on a limb here and guess that you aren’t exactly thrilled at the prospect of learning how to validate code identifiers. And really, who needs all that hassle and headache? How about I show you a different way to do it? A way that requires almost no effort whatsoever. An API is about to rescue us from our boring fate.

Let’s start things up by installing our API client with this command here:

composer require cloudmersive/cloudmersive_validate_api_client

Now we can call this function and configure our input rules concerning whitespace, hyphens, etc.

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

Now enter a code identifier to test it out, because it’s already working! It’s as simple as that.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet