How to Validate a VAT Number using Java

Vat numbers can be invalid for several reasons — most commonly due to improper formatting. Whatever the case, it’s important to ensure that VAT codes are entered correctly into any application or database, or you’ll have bigger problems to deal with down the line.

Thankfully, you can easily validate your VAT numbers through our VAT Validation API. The API response will provide a Boolean for the value IsValid, and can further identify BusinessName, BusinessAddress, and much more (only if this additional information is made available via the VAT code). The below example response shows a full list of possible values:

You can easily take advantage of this API for free — all you need to do is register a free account on our website, which will provide you with an API key good for 800 API calls per month (with zero additional financial commitments; perfect for small-scale projects and startups).

First, we need to install the API client. Let’s add a reference to the repository in pom.xml:

Next, let’s add a reference to the dependency in pom.xml:

With installation complete, let’s shift focus over to the controller and add the following imports to the top of our file:

Last but not least, let’s call the function & authenticate our API key on the fourth line down (indicated in the code comments):

We’ll want to pass our VAT code through the function in the following format:

And that’s it — no more code required. Easy as can be!



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

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