Skip to main content

Phone validation

PhoneNumberValidationAsync() checks whether a phone number is valid and returns it in national and international format, with its country and network.

Phone.cscsharp
using IdealPostcodes;

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

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

if (result is PhoneNumber phone)
{
Console.WriteLine($"{phone.InternationalFormat} {phone.Country} {phone.OriginalCarrier?.Name}");
}

Include the country code. A UK number can start +44, 44 or 0044. Your key needs phone validation enabled.

Result​

A valid number returns a PhoneNumber with:

PropertyExample
NationalFormat020 7112 8019
InternationalFormat+44 20 7112 8019
IsoCountry and IsoCountry2GBR and GB
CountryUnited Kingdom
OriginalCarrierA Carrier for the network the number was first assigned to, with Name and NetworkType such as mobile or landline

An invalid number returns an InvalidPhoneNumber with Valid false and every other property null. It is not an error, so check the class before reading the formats. Valid is on IPhoneNumberResponseResult.

Current network​

Set CurrentCarrier = "true" on the parameters to fill CurrentCarrier on the result as well. A number can move to another network, so OriginalCarrier alone can be out of date. The extra check can be slow, depending on the network, so allow for it in your request timeout.

Carrier.cscsharp
var result = (await client.PhoneNumberValidationAsync(new PhoneNumberValidationParams("+44 20 7112 8019") { CurrentCarrier = "true" })).Result;

Cost​

One lookup per request, including numbers that are invalid or fail to parse.

See PhoneNumberValidationAsync() for the parameters and the phone validation guide for how the checks work.