Skip to main content

$client->phoneNumberValidation()

Phone Number Validation

Validates a phone number and returns its country, its national and international formats, and the network it was originally assigned to.

Requires an API Key licensed for phone validation.

Every query decrements your lookup balance, including a number that fails to parse and a number reported as invalid.

Endpoint​

GET /phone_numbers

See the API reference for this endpoint.

Signature​

public function phoneNumberValidation(array $params): PhoneNumberResponse

Arguments​

NameTypeRequiredDescription
$paramsarrayyesQuery parameters. Keys under Query Parameters.

Query Parameters​

Pass these as keys of $params.

NameTypeRequiredDescription
querystringyesSpecifies the phone number to validate. Phone number must include a country code in an acceptable format. For instance, UK phone numbers should be prefixed with +44, 44 or 0044.
current_carrier'true'noWhen set to true, the API retrieves and populates the current network of the phone number.
tagsstring|list<string>noTags

Response​

IdealPostcodes\Responses\PhoneNumberResponse. Read fields as properties, such as $response->result, or as an array with the API's field names. toArray() returns the decoded body.

Errors​

An HTTP error throws ApiException with the HTTP status, the API error code from getCode() and the decoded body. A transport failure throws TransporterException. See error handling.

Example​

phone-number-validation.phpphp
<?php

declare(strict_types=1);

use IdealPostcodes\IdealPostcodes;
use IdealPostcodes\Types\PhoneNumber;

require 'vendor/autoload.php';

$client = IdealPostcodes::client('ak_test');

$response = $client->phoneNumberValidation(['query' => '+44 20 7112 8019']);

$result = $response->result;

if ($result instanceof PhoneNumber) {
echo $result->internationalFormat, ' (', $result->country, ')', PHP_EOL;
} else {
echo 'Invalid phone number', PHP_EOL;
}