pollin14/laravel-curp-validation

A set of validation rules specific to validate Mexico's CURP.

v1.0.2 2021-01-27 23:10 UTC

This package is auto-updated.

Last update: 2024-10-28 06:55:15 UTC


README

Software License codecov Workflow Total Downloads Version

A set of validation rules specific to validate Mexico's CURP.

It requires Laravel >= 5 and PHP >= 7.2.

Install

composer require pollin14/laravel-curp-validation

Usage

If you are using Laravel >= 6 and PHP >= 7.3 then you can install

composer require illuminatech/validation-composite

and use CurpRule.

<?php

use Illuminate\Contracts\Validation\Factory;
use Pollin14\LaravelCurpValidation\Rules\CurpRule;

$validator = app(Factory::class)->make(
            ['curp' => 'ABCD123456HABCDEF01'],
            ['curp' => ['required', new CurpRule()]]
        );

Of course, you can use the validations rules individuality

<?php 

use Illuminate\Contracts\Validation\Factory;
use Pollin14\LaravelCurpValidation\Rules\CurpBirthdate;
use Pollin14\LaravelCurpValidation\Rules\CurpGender;
use Pollin14\LaravelCurpValidation\Rules\CurpLastConsonants;
use Pollin14\LaravelCurpValidation\Rules\CurpLastDigit;
use Pollin14\LaravelCurpValidation\Rules\CurpLength;
use Pollin14\LaravelCurpValidation\Rules\CurpPenultimateChar;
use Pollin14\LaravelCurpValidation\Rules\CurpStartWithFourLetters;
use Pollin14\LaravelCurpValidation\Rules\CurpState;

$rules = [
    'curp_length',
    'curp_date',
    'curp_gender',
    'curp_start_with_4_letters',
    'curp_last_digit',
    'curp_penultimate_char',
    'curp_state',
    'curp_birthdate'
];

// Or if you are using Lumen
$rules = [
    new CurpLength(),
    new CurpGender(),
    new CurpStartWithFourLetters(),
    new CurpLastDigit(),
    new CurpPenultimateChar(),
    new CurpState(),
    new CurpBirthdate(),
    new CurpLastConsonants(),
] 

$validator = app(Factory::class)->make(
            ['curp' => 'ABCD123456HABCDEF01'],
            ['curp' => $rules]
        );

Testing

Run the tests with:

vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email victor.aguilar@ciencias.unam.mx instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.