Add real-time EU VAT number validation to your Next.js app. Validates against VIES and returns company details.
- Get your API key at eurovalidate.com
- Clone and install
git clone https://github.com/eurovalidate/nextjs-vat-validation.git cd nextjs-vat-validation npm install - Configure environment
cp .env.example .env.local # Edit .env.local with your EuroValidate API key - Run
npm run dev # Open http://localhost:3000
- React form (
app/page.tsx) with VAT number input and real-time validation - API route (
app/api/validate/route.ts) that calls EuroValidate server-side (API key stays secret) - Displays company name, address, confidence level, and response time
API Route (app/api/validate/route.ts):
import { EuroValidate } from "@eurovalidate/sdk";
const eurovalidate = new EuroValidate(process.env.EUROVALIDATE_API_KEY!);
export async function POST(request: NextRequest) {
const { vatNumber } = await request.json();
const result = await eurovalidate.vat.validate(vatNumber);
return NextResponse.json(result);
}React Component (app/page.tsx):
const res = await fetch("/api/validate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ vatNumber }),
});
const data = await res.json();
// data.data.valid, data.data.company_name, etc.{
"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