# `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](/docs/api/phone-number-validation.md) for this endpoint.

## Signature

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

## Arguments

| Name                | Type                          | Required | Description                                                           |
| ------------------- | ----------------------------- | -------- | --------------------------------------------------------------------- |
| `query`             | `PhoneNumberValidationParams` | yes      | Query parameters. Fields under [Query Parameters](#query-parameters). |
| `cancellationToken` | `CancellationToken`           | no       | Cancels 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.

| Name              | Type     | Required | Description                                                                                                                                                                             |
| ----------------- | -------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `query`           | `string` | yes      | Specifies 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` | `string` | no       | When set to `true`, the API retrieves and populates the current network of the phone number.                                                                                            |
| `tags`            | `string` | no       | Tags                                                                                                                                                                                    |

## Response

`PhoneNumberResponse`. Fields are properties in PascalCase, such as `response.Result`; fields this SDK version does not know are kept in `AdditionalProperties`. See [responses](/docs/sdks/dotnet/responses.md).

## 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](/docs/sdks/dotnet/errors.md).

## Example

phone-number-validation.cscsharp

```csharp
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");
}
```
