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

## Signature

```go
func (c *Client) PhoneNumberValidation(ctx context.Context, query string, params *PhoneNumberValidationParams) (*PhoneNumberResponse, error)
```

## Arguments

| Name     | Type                           | Required | Description                                                                                                                                                                             |
| -------- | ------------------------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ctx`    | `context.Context`              | yes      | Cancels the request and sets its deadline.                                                                                                                                              |
| `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`. |
| `params` | `*PhoneNumberValidationParams` | no       | Optional query parameters, or nil. Fields under [Query Parameters](#query-parameters).                                                                                                  |

## Query Parameters

A required parameter is a method argument. Set the rest as fields of `params`, named in Studly case (`post_town` is `PostTown`); a field left at its zero value is not sent.

| 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

`*addresszen.PhoneNumberResponse`. Fields the API may leave out or send as null are pointers. `RawJSON()` returns the body as received. See [responses](/docs/sdks/go/responses.md).

## Errors

An HTTP error returns `*addresszen.APIError` with the HTTP status, the API error code and the body; match it with `errors.AsType`. A transport failure returns the `net/http` error, wrapped. See [error handling](/docs/sdks/go/errors.md).

## Example

phone-number-validation/main.gogo

```go
package main

import (
	"context"
	"fmt"
	"log"

	addresszen "go.addresszen.com/sdk"
)

func main() {
	client := addresszen.NewClient("ak_test")
	res, err := client.PhoneNumberValidation(context.Background(), "+1 202 555 0123", nil)
	if err != nil {
		log.Fatal(err)
	}
	if phone := res.Result.AsPhoneNumber(); phone != nil {
		fmt.Printf("%s (%s)\n", phone.InternationalFormat, phone.Country)
		return
	}
	fmt.Println("Invalid phone number")
}
```
