Add EU VAT number validation to your Django app. Includes a form validator, view, and template with real-time VIES lookup.
- Get your API key at eurovalidate.com
- Clone and install
git clone https://github.com/eurovalidate/django-vat-validation.git cd django-vat-validation python -m venv venv && source venv/bin/activate pip install -r requirements.txt
- Configure environment
cp .env.example .env # Edit .env with your EuroValidate API key - Run
python manage.py runserver # Open http://localhost:8000
- Django Form (
vat_app/forms.py) with client-side format validation (country prefix, length, EU country codes) - View (
vat_app/views.py) that calls EuroValidate API on form submit - Template (
vat_app/templates/validate.html) showing VAT status, company name, address, and confidence level
Form with VAT validation (vat_app/forms.py):
class VATForm(forms.Form):
vat_number = forms.CharField(max_length=20)
def clean_vat_number(self):
vat = self.cleaned_data["vat_number"].strip().upper()
# Validates format: country prefix, length, EU country codes
return vatView calling EuroValidate (vat_app/views.py):
from eurovalidate import EuroValidate
client = EuroValidate(api_key=settings.EUROVALIDATE_API_KEY)
response = client.vat.validate(vat_number)
result = {
"valid": response.data.valid,
"company_name": response.data.company_name,
"company_address": response.data.company_address,
"confidence": response.meta.confidence,
}{
"success": true,
"data": {
"valid": true,
"vat_number": "NL820646660B01",
"country_code": "NL",
"company_name": "COOLBLUE B.V.",
"company_address": "WEENA 00664 3012CN ROTTERDAM"
},
"meta": {
"confidence": "HIGH",
"source": "vies_live",
"cached": false,
"response_time_ms": 47
}
}| VAT Number | Country | Company |
|---|---|---|
NL820646660B01 |
Netherlands | Coolblue B.V. |
FR40303265045 |
France | Google France |
MIT