Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
cedula-panama
Advanced tools
Valida si una cadena texto es una cédula panameña válida. El validador se puede utilizar para validar una cédula completa o para validar el formato mientras un usuario escribe en un campo de texto.
Validates 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
}
# incomplete, but valid string
{
isValid: true,
inputString: '8-123-'
isComplete: false,
cedula: [undefined, undefined, undefined, undefined]
}
# complete #1
{
isValid: true,
inputString: '8-123-123',
isComplete: true,
cedula: ["8", "", "123", "123"]
}
# complete #2
{
isValid: true,
inputString: 'PE-123-123',
isComplete: true,
cedula: ["0", "PE", "123", "123"]
}
Primero, importa en la cabecera el fichero a cedula.js en la cabecera head.
In order to use it, first include in the head the cedula.js file:
<!-- in your head -->
<script src="../cedula.js"></script>
Ya puedes usar la función validateCedula(cedula) After that, you can use the function validateCedula(cedula)
Ejemplo / Example::
<html>
<head>
<script src="../cedula.js"></script> <!-- set the path to your local copy of cedula.js -->
<script>
function validate(cedula) {
var result = validateCedula(cedula)
document.getElementById('isValid').innerHTML= result.isValid;
document.getElementById('inputString').innerHTML= result.inputString;
document.getElementById('isComplete').innerHTML= result.isComplete;
document.getElementById('separated').innerHTML= result.cedula != null ? result.cedula.toString() : "null";
}
</script>
</head>
<body>
<h1>Validador javascript del formato de la cédula de Panamá</h1>
<p>Ejemplo:</p>
<input type="text" id="cedula" onkeyup="validate(this.value)" autofocus placeholder="Ej: 8-123-456">
<p>
<strong>Result:</strong>
<br>cedula.isValid = <span id="isValid"></span>
<br>cedula.inputString = <span id="inputString"></span>
<br>cedula.isComplete = <span id="isComplete"></span>
<br>cedula.separated = <span id="separated"></span>
</p>
</body>
</html>
Identificación de las provincias
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](?:A|P)?|1[0123]?|1[0123]?(?:A|P)?)$|^(?:PE|E|N|[23456789]|[23456789](?:AV|PI)?|1[0123]?|1[0123]?(?:AV|PI)?)-?$|^(?:PE|E|N|[23456789](?:AV|PI)?|1[0123]?(?:AV|PI)?)-(?:\d{1,4})-?$|^(PE|E|N|[23456789](?:AV|PI)?|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](?:AV|PI)?|1[0123]?(?:AV|PI)?)-(\d{1,4})-(\d{1,6})$/i
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.
FAQs
A simple validator of the Panamenian id (cedula)
We found that cedula-panama demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.