DEV Community

Cover image for How to Validate DNI, NIE, CIF, and International Tax IDs in Your Backend
Jose Luis Bermejo Meléndez
Jose Luis Bermejo Meléndez

Posted on

How to Validate DNI, NIE, CIF, and International Tax IDs in Your Backend

Stop writing complex custom regexes for every country — validate format structures and checksums with a single lightweight API call.

Global ID format validation architecture

Handling identity document validation across international markets is a recurring pain point for software engineering teams. When onboarding users, entering invalid IDs or typos leads to corrupted database entries, failed billing pipelines, and compliance headaches. Writing custom regular expressions (regex) or local checksum algorithms (like Luhn or specific country rules) for dozens of countries quickly becomes an unmaintainable mess.

The Solution: Format Validation at the Input Stage

Instead of building and updating validation logic for every nation from scratch, you can offload structure and checksum validation to Luhnify, a free, lightweight API designed for real-time format verification across 200+ countries.

It checks the structure, character rules, and mathematical validity (checksums) without storing sensitive payload data or requiring slow biometric KYC processes.
Quick Integration Example

Here is how simple it is to validate an international ID using a single HTTP request:

curl -X POST https://api.luhnify.com/api/v1/validate \
  -H "X-API-KEY: your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "document_number": "12345678A",
    "document_type": "dni",
    "country_code": "ES"
  }'
Enter fullscreen mode Exit fullscreen mode

You receive a clean JSON payload indicating whether the format and checksum are valid, allowing your frontend or backend to immediately accept or prompt the user for corrections:

{
  "valid": true,
  "message": "Document is valid."
}
Enter fullscreen mode Exit fullscreen mode

Key Benefits

  • Ultra-fast Performance: Average response time under 50 ms, perfect for real-time form validation without slowing down user onboarding.
  • 200+ Countries supported: Standardized responses regardless of nationality.
  • 8 Official SDKs: Ready-to-use packages for PHP (Laravel, Symfony, native PHP), TypeScript, Java, Go, C#, Swift, Kotlin, and Python. Drop it into your stack with zero setup friction.
  • Zero PII Storage: High performance without unnecessary data retention risks.
  • Developer First: Built by engineers to keep onboarding forms clean and database inputs valid.

Try it out for free at luhnify.com and keep your registration flow clean!

Top comments (0)