Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

This module provides a backend API for validating personal identification documents from various countries, using a plugin system for easy extensibility. It helps ensure that national ID formats and structures are correct during form submissions or data synchronization.

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
1 year ago
Releases (12 mo)
0 ▼ from 2
Maintenance
Dormant

Releases

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