A simple validator of the Panamenian id (cedula)
npm install cedula-panamaValidates if a string is a valid Panamenian cedula. The validator can be used either for checking a complete string or for testing while typing in an input box if it is a valid cedula format.
$ npm install cedula-panama
El validador es muy simple, tiene una función _validateCedula(cedula)_ que recibe la cédula como parámetro y devuelve un objeto de la forma:
_The validator is pretty simple, it just has a function validateCedula(cedula) that receives a cedula string as parameter and returns an object like: this_
``
{
isValid: true|false, # booleano que indica si la cadena podría formar parte de una cédula (true).
# true if the string could be a valid cedula, useful while typing.
inputString: cedula, # es el parámetro de entrada.
# Input value.
isComplete: true|false, # booleano que indica si la cadena es una cédula completa.
# boolean that tells if it is a complete cedula.
cedula: ["1","2","3","4"] # Array con los campos de la cédula (provincia, letra, libro, tomo) separados.
# null - si isValid == false.
# [undefined, undefined, undefined, undefined] - si isComplete == false.
# [1,2,3,4] - Valores de la cédula si esta es válida y completa (isValid == isComplete == true).
# Array with the separated components of the cedula (province, letters, book, volume).
# null - if isValid == false.
# [undefined, undefined, undefined, undefined] - if isComplete == false.
# ["1","2","3","4"] - Values of the cedula if it is valida and complete (isValid == isComplete == true).
}
`
Ejemplos / _Examples_ :
`not valid
{
isValid: false,
inputString: '88-BB',
isComplete: false,
cedula: null
}
`
_In order to use it, first include in the head the cedula.js file:_
`html`
Ya puedes usar la función validateCedula(cedula)
_After that, you can use the function validateCedula(cedula)_
Ejemplo / _Example:_:
`html
Validador javascript del formato de la cédula de Panamá
Ejemplo:
Result:
cedula.isValid =
cedula.inputString =
cedula.isComplete =
cedula.separated =
Patrones aceptados / _Accepted patterns_
* Regular (provincia-libro-tomo). Ej: 1-1234-12345
* Panameño nacido en el extranjero (PE-libro-tomo). Ej: PE-1234-123456
* Extranjero con cédula (E-libro-tomo). Ej: E-1234-12345
* Naturalizado (N-libro-tomo). Ej: N-1234-12345
* Panameños nacidos antes de la vigencia (provinciaAV-libro-tomo). Ej: 1AV-1234-12345
* Población indigena (provinciaPI-libro-tomo). Ej: 1PI-1234-12345
Identificación de las provincias
1. Bocas del Toro
2. Coclé
3. Colón
4. Chiriquí
5. Darién
6. Herrera
7. Los Santos
8. Panamá
9. Veraguas
10. Guna Yala
11. Emberá Wounaan
12. Ngäbe-Buglé
13. Panamá Oeste
Cómo puedo portarlo a otros lenguajes de programacin / Porting to other languages
La validación de la cédula se hace a través de una expresión regular que está en _cedula.js_.
Esta expresión está pensada para ser usada mientras se escribe la cédula en un campo de texto.
Esta es la expresión regular completa:
`
/^P$|^(?:PE|E|N|[23456789]|23456789?|1[0123]?|1[0123]?(?:A|P)?)$|^(?:PE|E|N|[23456789]|23456789?|1[0123]?|1[0123]?(?:AV|PI)?)-?$|^(?:PE|E|N|23456789?|1[0123]?(?:AV|PI)?)-(?:\d{1,4})-?$|^(PE|E|N|23456789?|1[0123]?(?:AV|PI)?)-(\d{1,4})-(\d{1,6})$/i
`Si lo que quieres es validar si una cadena tiene el formato válido de una cédula, la expresión
regular debería ser:
`
/^(PE|E|N|23456789?|1[0123]?(?:AV|PI)?)-(\d{1,4})-(\d{1,6})$/i
`Pruebas unitarias / Tests
El paquete incluye un conjunto de tests que permiten validar el funcionamiento.
_The package includes unit test that can be run_
`
$ npm test
``
Copyright (c) 2017 Juan M. Merlos (@merlos)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.