Skip to main content

client.PhoneNumberValidationAsync()

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​

Task<PhoneNumberResponse> PhoneNumberValidationAsync(PhoneNumberValidationParams query, CancellationToken cancellationToken = default)

Arguments​

NameTypeRequiredDescription
queryPhoneNumberValidationParamsyesQuery parameters. Fields under Query Parameters.
cancellationTokenCancellationTokennoCancels the request.

Query Parameters​

Set these on the query argument. Each property is the name in PascalCase, such as PostTown for post_town; required fields are constructor arguments.

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_carrierstringnoWhen set to true, the API retrieves and populates the current network of the phone number.
tagsstringnoTags

Response​

PhoneNumberResponse. Fields are properties in PascalCase, such as response.Result; fields this SDK version does not know are kept in AdditionalProperties. See responses.

Errors​

An HTTP error throws ApiException with the StatusCode, the API error Code and the raw Body. A success response whose body cannot be read throws UnserializableResponseException. Network failures and cancellation throw HttpClient's own HttpRequestException and OperationCanceledException. See error handling.

Example​

phone-number-validation.cscsharp
using IdealPostcodes;

using var client = new IdealPostcodesClient("ak_test");

var response = await client.PhoneNumberValidationAsync(new PhoneNumberValidationParams("+44 20 7112 8019"));

if (response.Result is PhoneNumber result)
{
Console.WriteLine($"{result.InternationalFormat} ({result.Country})");
}
else
{
Console.WriteLine("Invalid phone number");
}