Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

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
11 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