All Projects → merlos → cedula-panama

merlos / cedula-panama

Licence: MIT License
Validador javascript de la cédula de panama. A javascript validator of the Panamenian id (cedula)

Programming Languages

javascript
184084 projects - #8 most used programming language
python
139335 projects - #7 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to cedula-panama

goimpulse
高可用,高性能的分布式发号服务
Stars: ✭ 17 (-34.62%)
Mutual labels:  id
id-mask
IDMask is a Java library for masking internal ids (e.g. from your DB) when they need to be published to hide their actual value and to prevent forging. It has support optional randomisation has a wide support for various Java types including long, UUID and BigInteger. This library bases its security on strong cryptographic primitives.
Stars: ✭ 39 (+50%)
Mutual labels:  id
leafserver
🍃A high performance distributed unique ID generation system
Stars: ✭ 31 (+19.23%)
Mutual labels:  id
rig
RIG - A Randomised ID Card Generator
Stars: ✭ 20 (-23.08%)
Mutual labels:  id
platform device id
flutter plugin to get device id
Stars: ✭ 32 (+23.08%)
Mutual labels:  id
ids
高效的分布式id生成器,每个客户端实例tps可达到100万,服务端毫无压力。即使服务端宕机了,id生成依然可用。支持多数据中心,支持id加密。
Stars: ✭ 47 (+80.77%)
Mutual labels:  id
DocumentReader-iOS
iOS Framework for reading and validation of identification documents
Stars: ✭ 54 (+107.69%)
Mutual labels:  id
sid
Generate Sortable Identifiers
Stars: ✭ 26 (+0%)
Mutual labels:  id
distributed-id
基于netty4+twitter-snowFlake分布式Id生成之服务实现
Stars: ✭ 18 (-30.77%)
Mutual labels:  id
ulid-creator
A Java library for generating Universally Unique Lexicographically Sortable Identifiers (ULID)
Stars: ✭ 38 (+46.15%)
Mutual labels:  id
gid
Golang 分布式ID生成系统,高性能、高可用、易扩展的id生成服务
Stars: ✭ 55 (+111.54%)
Mutual labels:  id
firebase-id-tokens-verifier
Code snippet to show how to verify Firebase ID tokens using Ruby
Stars: ✭ 32 (+23.08%)
Mutual labels:  id
hide
ID type with marshalling to/from hash to prevent sending IDs to clients.
Stars: ✭ 45 (+73.08%)
Mutual labels:  id
sandid
Every grain of sand on Earth has its own ID.
Stars: ✭ 39 (+50%)
Mutual labels:  id
tsid-creator
A Java library for generating Time Sortable Identifiers (TSID).
Stars: ✭ 16 (-38.46%)
Mutual labels:  id
hashids.sql
PL/pgSQL implementation of hashids library
Stars: ✭ 40 (+53.85%)
Mutual labels:  id
vue-uniq-ids
Vue.js 2.x plugin that helps to use id-related attributes with no side-effect
Stars: ✭ 32 (+23.08%)
Mutual labels:  id
mongoose-auto-increment-reworked
An auto-incrementing field generator for Mongoose 4 & 5
Stars: ✭ 17 (-34.62%)
Mutual labels:  id
urbit-visor
Urbit Visor is an extension which transforms your web browser into a first class Urbit client.
Stars: ✭ 65 (+150%)
Mutual labels:  id
chinaid
🇨🇳中国大陆身份证号解析/校验
Stars: ✭ 18 (-30.77%)
Mutual labels:  id

Validador de cédula de Panamá / Validator for the Panamenian id cedula_

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.

VER DEMO

Disponible en los siguientes lenguajes de programación en este repositorio:

En otro repositorio:

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.

Javascript

Instalación / Installation

$ npm install cedula-panama

Documentación

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"]
}

Modo de empleo / Usage

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>

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

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

Cómo puedo portarlo a otros lenguajes de programación / 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](?: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

¡Hey! Si lo portas a otro lenguage puedes hacer un push request a este repo (si quieres que se distribuya aquí) o si lo distribuyes en otro déjanos un issue para que lo enlacemos desde aquí.

Python

Hay un ejemplo en example.py.

An example is provided in example.py.

# example.py
from cedula import validate as validate_id

# validate_id(cedula_as_a_string)
print(validate_id('4-564-2343'))

# output
# {
#   'is_valid': True,
#   'input': '4-564-2343',
#   'is_complete': True,
#   'id': ['', '4', '564', '2343'],
#   'unified': '004056402343'
# }

Ejecuta:

 $ python3 example.py

Agradecimientos / Acknowledgements

Licencia MIT / MIT License

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].