Skip to content

ltns35/go-vat

Repository files navigation

Go VAT

GitHub go.mod Go version of a Go module Maintenance

Check the validity of a VAT number without any HTTP request.

This go library is based on the original jsVAT for JS/TS.

The intention of this library is to offer to all gophers the ability to validate all the VAT numbers before they are stored in a database.

⚙️ Installation

Go v1.17.x or newer (RECOMMENDED)

go install github.com/ltns35/go-vat

Go v1.16.x or older

go get -u github.com/ltns35/go-vat

🎯 Features

  • Check the validity of VAT numbers.
  • Extendable with custom countries/rules
  • Offline

📚 How to use

// Check against all supported countries validators.
vatResult, err := vat.Validate("ADE000000E")
if err != nil {
// Handle error
}

// Check ONLY against Andorra validator.
countries := []countries.Calculer{
countries.Andorra,
}
vatResult, err = vat.Validate("ADE000000E", countries...)

// output: vatResult
//
//	{
//	   "value":"ADF000000F",
//	   "isValid":true,
//	   "isSupportedCountry":true,
//	   "country":{
//	      "name":"Andorra",
//	      "codes":[
//	         "AD",
//	         "AND",
//	         "020"
//	      ],
//	      "rules":{
//	         "multipliers":null,
//	         "typeFormats":null,
//	         "lookup":null,
//	         "check":"",
//	         "regex":[
//	            "^(AD)([fealecdgopuFEALECDGOPU]{1}\\d{6}[fealecdgopuFEALECDGOPU]{1})$"
//	         ],
//	         "additional":null
//	      }
//	   }
//	}
//

🌍 Supported countries

  • Albania
  • Andorra
  • Argentina
  • Austria
  • Belarus
  • Belgium
  • Bolivia
  • Brazil
  • Bulgaria
  • Canada
  • Croatia
  • Cyprus
  • Czech Republic
  • Denmark
  • Ecuador
  • Estonia
  • Europe
  • Finland
  • France
  • Germany
  • Greece
  • Guatemala
  • Hungary
  • Hong Kong
  • India
  • Indonesia
  • Ireland
  • Italy
  • Kazakhstan
  • Korea, Republic of
  • Latvia
  • Liechtenstein
  • Lithuania
  • Luxembourg
  • Malaysia
  • Malta
  • Netherlands
  • New Zealand
  • Nigeria
  • North Macedonia
  • Norway
  • Peru
  • Poland
  • Portugal
  • Romania
  • Russia
  • San Marino
  • Serbia
  • Slovakia
  • Slovenia
  • Spain
  • Sweden
  • Switzerland
  • Taiwan
  • Turkey
  • Ukraine
  • United Kingdom
  • Uruguay

🧭 Need an unsupported country

If you need a country is not yet supported by the library open a new issue or create a pull request to be merged.

🧪 Testing

The library is tested against the 2 latest stable major versions of Go.

  • 1.17.x
  • 1.16.x

All the validators has been tested individually to ensure the correct working, if you need more tests don't hesitate to open a new issue with the values you want to be tested.

⚠️ LICENSE

The library is under the MIT license, so you can use it for free for commercial products.