Giter Club home page Giter Club logo

php-mx-curp's Introduction

Herramientas en PHP para CURP de México

Conjunto de herramientas en PHP para la validación de la Cláve Única de Registro de Población en México.

Instalación

La instalación se puede realizar mediante composer.

composer require francerz/mx-curp

Utilización

use Francerz\MX_CURP\CURP;
use Francerz\MX_CURP\EntidadesFederativasEnum;
use Francerz\MX_CURP\SexosEnum;

$curp = new CURP('PERJ911109HCMRDN05');

/*
    VALIDAR CURP
    - Verifica estructura de la cadena.
    - Verifica presencia de palabras inconvenientes.
    - Prueba congruencia del dígito verificador.
*/
if (!$curp->esValida()) {
    throw new Exception("La CURP introducida es inválida.");
}

/*
    OBTENER FECHA DE NACIMIENTO
    Obtiene la fecha de nacimiento presente en la CURP en un objeto
    DateTimeImmutable.
*/
$fechaNacimiento = $curp->getFechaNacimiento();
// Salida: 1991-11-09T00:00:00+00:00
echo $fechaNacimiento->format(DateTimeInterface::W3C) . PHP_EOL;

/*
    OBTENER SEXO
    Obtiene el valor representativo del sexo
*/
switch ($curp->getSexo()) {
    case SexosEnum::HOMBRE:
        echo "Es HOMBRE" . PHP_EOL;
        break;
    case SexosEnum::MUJER:
        echo "Es MUJER" . PHP_EOL;
        break;
}

/*
    OBTENER ENTIDAD DE NACIMIENTO
    Obtiene los dígitos característicos de la entidad federativa de nacimiento.
*/
switch ($curp->getEntidadFederativa()) {
    case EntidadesFederativasEnum::AGUASCALIENTES:
        echo "Nació en Aguascalientes." . PHP_EOL;
        break;
    case EntidadesFederativasEnum::COLIMA:
        echo "Nació en Colima." . PHP_EOL;
        break;
    case EntidadesFederativasEnum::ZACATECAS:
        echo "Nació en Zacatecas." . PHP_EOL;
        break;
    case EntidadesFederativasEnum::NACIDO_EXTRANJERO:
        echo "Nació en el Extranjero." . PHP_EOL;
        break;
}

/*
    VERIFICAR CORRESPONDIENCIA DEL NOMBRE
    Realiza pruebas de los caracteres clave del nombre(s) para verificar su
    correspondencia.
*/
if (!$curp->esNombreValido('Juan')) {
    throw new Exception('El nombre no corresponde a la CURP.');
}

/*
    VERIFICAR CORRESPONDIENCIA DEL PRIMER APELLIDO
    Realiza pruebas de los caracteres clave del primer apellido para verificar
    su correspondencia.
*/
if (!$curp->esApellido1Valido('Pérez')) {
    throw new Exception('El primer apellido no corresponde a la CURP.');
}

/*
    VERIFICAR CORRESPONDIENCIA DEL SEGUNDO APELLIDO
    Realiza pruebas de los caracteres clave del segundo apellido para verificar
    su correspondencia.
*/
if (!$curp->esApellido2Valido('Rodríguez')) {
    throw new Exception('El segundo apellido no corresponde a la CURP.');
}

echo "Todo parece estar en orden." . PHP_EOL;

php-mx-curp's People

Contributors

francerz avatar

Watchers

 avatar

Forkers

cmendez2121

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.