How to validate a VAT number using C# in .NET Framework
1 min readSep 20, 2019
Let’s take a look at how to quickly and easily look up and validate VAT numbers within .NET Framework. It’s a lot easier than you might think. Let’s get started.
First, install Cloudmersive’s Validate API using the Package Manager console:
Install-Package Cloudmersive.APIClient.NET.Validate -Version 1.2.7
Then call VatVatLookup and input your VAT code.
using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.Validate.Api;
using Cloudmersive.APIClient.NET.Validate.Client;
using Cloudmersive.APIClient.NET.Validate.Model;namespace Example
{
public class VatVatLookupExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new VatApi();
var input = new VatLookupRequest(); // VatLookupRequest | Input VAT codetry
{
// Lookup a VAT code
VatLookupResponse result = apiInstance.VatVatLookup(input);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling VatApi.VatVatLookup: " + e.Message );
}
}
}
}
That’s it! Your return will include whether the number is valid, as well as the business name, address, and country code.