How to validate a VAT number in Java

VAT numbers can be a huge boon come tax season, but looking up numbers manually is a hassle that you should not have to deal with. Today we will be looking at a much easier way to tackle this problem. Let’s set up an automated system for VAT number validation in just a couple of minutes using Java.

First we need to add references to our Maven POM file so that our library can be dynamically compiled via Jitpack.

Repository reference:


Dependency reference:


Now that that’s done, we simply call vatVatLookup:

// Import classes://import com.cloudmersive.client.invoker.ApiClient;//import com.cloudmersive.client.invoker.ApiException;//import com.cloudmersive.client.invoker.Configuration;//import com.cloudmersive.client.invoker.auth.*;//import com.cloudmersive.client.VatApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");Apikey.setApiKey("YOUR API KEY");// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.setApiKeyPrefix("Token");VatApi apiInstance = new VatApi();VatLookupRequest input = new VatLookupRequest(); // VatLookupRequest | Input VAT codetry {VatLookupResponse result = apiInstance.vatVatLookup(input);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling VatApi#vatVatLookup");e.printStackTrace();}

We will be given back a response in the following format:

"CountryCode": "string",
"VatNumber": "string",
"IsValid": true,
"BusinessName": "string",
"BusinessAddress": "string",
"BusinessBuilding": "string",
"BusinessStreetNumber": "string",
"BusinessStreet": "string",
"BusinessCity": "string",
"BusinessStateOrProvince": "string",
"BusinessPostalCode": "string",
"BusinessCountry": "string"

As you can see, we are provided the validity of the number, as well as plenty of useful information about the company in question.

Image for post

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store