International Personal Documentation Validator
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.