Drupal is a registered trademark of Dries Buytaert

ipd_validator

No security coverage
View on drupal.org

International Personal Documentation Validator (IPD Validator)

The IPD Validator module provides an extensible, service-based API to validate personal identification documents (like DNI, CUIT, CUIL, etc.) for different countries.
It is designed for backend use only β€” there is no user interface.

πŸ” Why use this module?

  • βœ… Need to validate national ID numbers during profile registration or form submissions?
  • βœ… Want to enforce country-specific document formatting and structure?
  • βœ… Looking for an easily extensible plugin-based API for validators?

If you answered yes to any of the above, IPD Validator is for you.

πŸ’‘ Use cases

  • Form validation for user registration, profile update, or custom forms.
  • Validation before syncing data to external CRMs or APIs that require valid ID numbers.
  • Backend sanitization of personal ID inputs semantically tied to country-specific rules.

πŸ”Œ How it works

The module uses the Drupal Plugin API to provide document validators, each responsible for one country's logic. A validator plugin includes a country_code, label, description, and logic for isValid() and optional format().

The core service plugin.manager.ipd_validator exposes methods to:

  • validate($document, $countryCode)
  • format($document, $countryCode)
  • getSupportedCountries()

If no validator exists for a given country code, the document is considered valid by default.

🚫 No front-end interface

This module provides no block, form element, or end-user interface β€” it is intended for developers and is used programmatically.

πŸ”§ Example

// Using the Validator service.
$validator = \Drupal::service('plugin.manager.ipd_validator');

// Validate a CUIT (Argentina).
$is_valid = $validator->validate('20304050607', 'AR');

πŸ§ͺ Built-in validators

Currently includes support for:

  • AR – Argentina (DNI / CUIT / CUIL)
  • BD – Bangladesh (NID)
  • BO – Bolivia (CΓ©dula de Identidad)
  • BR – Brazil (CPF / CNPJ)
  • CI – CΓ΄te d'Ivoire (CNI)
  • CL – Chile (CI / RUT)
  • CM – Cameroon (CNI)
  • CN – China (Resident Identity Card)
  • CO – Colombia (CΓ©dula de CiudadanΓ­a)
  • CR – Costa Rica (CΓ©dula de Identidad)
  • EC – Ecuador (CΓ©dula de Identidad)
  • EG – Egypt (National ID)
  • GH – Ghana (Ghana Card)
  • GT – Guatemala (CUI)
  • HN – Honduras (DNI)
  • ID – Indonesia (NIK)
  • IN – India (PAN)
  • JO – Jordan (National ID Number)
  • JP – Japan (My Number)
  • KE – Kenya (National ID)
  • MA – Morocco (CNIE)
  • MX – Mexico (CURP)
  • MY – Malaysia (NRIC)
  • NE – Niger (CNI)
  • NG – Nigeria (NIN)
  • NI – Nicaragua (DNI)
  • PA – Panama (CΓ©dula)
  • PE – Peru (DNI)
  • PH – Philippines (PSN)
  • PK – Pakistan (CNIC)
  • PY – Paraguay (CI)
  • RW – Rwanda (National ID)
  • SA – Saudi Arabia (National ID)
  • SN – Senegal (CNI)
  • SV – El Salvador (DUI)
  • TH – Thailand (Personal ID)
  • TR – Turkey (T.C. Kimlik No)
  • TZ – Tanzania (National ID)
  • UG – Uganda (NIC)
  • UY – Uruguay (CI / RUT)
  • VN – Vietnam (VNID)
  • ZA – South Africa (ID Number)
  • ZM – Zambia (NRC)

Each validator encapsulates validation rules specific to the document structure and format required by the target country.

New validators can be added by implementing a simple plugin in your own module.

You can extend it easily by writing your own plugin via the @Validator annotation in a custom module.

πŸ§ͺ Tests

Includes both Unit and Kernel tests to ensure plugin stability and correct API behavior.

πŸš€ Future plans

  • Additional validators for more countries (Spain, Mexico, etc.).
  • Optional integration with form validation via hook or plugin manager wrapper.
  • Configurable response handling (log invalid documents, etc.).

πŸ‘€ Maintainer

Module created and maintained by Pedro PelΓ‘ez (PSF_).

🀝 Contributions and patches welcome!

Feel free to create issues or merge requests with new validator plugins or ideas to improve the module.

Activity

Total releases
2
First release
May 2025
Latest release
9 months ago
Release cadence
0 days
Stability
50% stable

Releases

Version Type Release date
1.0.0 Stable May 14, 2025
1.0.x-dev Dev May 14, 2025