A simple library to validate Mexican CURPs (Personal ID)

Overview

Validate CURP

A simple and lightweight library to validate Mexican CURPs (Personal ID).

Install

NodeJS

Use NPM:

$ npm install --save validate-curp

Or YARN:

$ yarn add validate-curp

Browser

Add the script to your project:

<!-- Latest version -->
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/validate-curp@latest/dist/index.js" type="text/javascript"></script>

<!-- Or specify a version -->
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/[email protected]/dist/index.js" type="text/javascript"></script>

<!-- This will export a global function "validateCurp": -->
<script type="text/javascript">
  var data = validateCurp('motr930411hjcrmn03');
  console.log(data);
</script>

API

The library only exposes a single function (.validateCurp).

.validateCurp(curp)

Checks whether a string is a valid CURP and returns validation details.

Parameters

Parameter Type Description
curp String The CURP to be validated.
options Object Settings (Optional).

Response

It returns a plain object with the values:

Parameter Type Description
isValid Boolean Indicates if the string is a valid CURP.
curp String The formatted CURP (uppercase, with no white spaces or symbols). Returns null when input is an invalid CURP.
errors Array[String] In case the CURP is invalid, the reasons why the CURP is invalid will be listed here.

Possible errors values and they description are:

Error Descripción
INVALID_FORMAT The format is invalid, that means, the string does not meet with the required length or expected structure. Eg: XYZ because clearly is not an CURP.
INVALID_DATE The string may have the correct format, but digits generate an invalid date. Eg: MOTR935511HJCRMN03 because it refers to month 55.
INVALID_STATE The string may have the correct format, but letters for state don't match with a valid one. Eg: MOTR9390411HXXRMN03 because it refers to state XX, which does not exist. See the valid states list here.
INVALID_CHECK_DIGIT The string has a valid format, but the last character (check digit) is invalid. Eg: MOTR930411HJCRMN09 ends with 9 but it is expected to end with 3.
FORBIDDEN_WORD The string contains one of the inconvenient words that cannot be included in a CURP. Eg: FETO930411HJCRMN03 the initials make the word FETO (fetus, LOL). Find the full list of words in this document.

Example

const validateCurp = require('validate-curp');

const response = validateCurp('motr930411hjcrmn03');
console.log(response);

/*
Prints:

{
  isValid: true,
  curp: 'MOTR930411HJCRMN03'
}

*/

const response = validateCurp('This is not a CURP');
console.log(response);

/*
Prints:

{
  isValid: false,
  curp: null,
  errors: ['INVALID_FORMAT']
}

*/

Tests

Run the test with the command:

$ yarn test

Related

  • validate-rfc
  • You need to check if an RFC is registered in SAT or is blacklisted? Try with Verifier.

Licencia

MIT

You might also like...

Just A Personal Card for Cristian Del Rio (CristianJDelRio)

Just A Personal Card for Cristian Del Rio (CristianJDelRio)

NPX CARD This my NPX card show you a little bit about me directly via console or terminal 👇 just hit npx cristianjdelrio SCREENSHOT The final output

Oct 26, 2021

A simple credit cards validation library in JavaScript

creditcard.js A simple credit cards validation library in JavaScript. Project website: https://contaazul.github.io/creditcard.js Install creditcard.js

Jan 7, 2023

Dead simple Object schema validation

Yup Yup is a JavaScript schema builder for value parsing and validation. Define a schema, transform a value to match, validate the shape of an existin

Jan 2, 2023

Simple and basic javascript form validations

JavaScript-Form-Validations Simple and basic javascript form validations Table of Validations: S. No. Type of validation Link 1 Non-empty text field h

Dec 17, 2022

Simple translation for your javascripts, yummy with your favorite templates engine like EJS.

jsperanto Simple translation for your javascripts, yummy with your favorite templates engine like EJS. Pluralization, interpolation & "nested lookup"

Oct 21, 2021

A simple environment variables validator for Node.js and web browsers

A simple environment variables validator for Node.js and web browsers

Jul 20, 2022

Simple password validator made with Javascript 💛

Simple password validator made with Javascript 💛

Password Validator Simple password validator made with Javascript 💛 Branch history base-code: a complex logic to password validator. In next branches

Jul 25, 2022

Simple, smart and pleasant validation solution.

nice-validator Simple, smart and pleasant validation solution. Download the latest release or install package via npm or bower $ npm install nice-vali

Nov 18, 2022
Owner
Manuel de la Torre
Developer, geek and nomad. Passionate about product design, photography, mountaineering, racing drones and traveling.
Manuel de la Torre
jQuery library to validate html forms. compatible with bootstrap v4 and bootstrap v3

jQuery form validation jQuery form validation is a library that helps you to validate your HTML form, it's completable with both Bootstrap 3 and Boots

Bassam Nabriss 33 Jun 10, 2021
A library for validate a string using regular expressions.

Fogex Form Regex Quickly and easily check if the content is valid. Installation npm install fogex or yarn add fogex Usage import fogex from 'fogex';

null 5 May 5, 2022
Validate your forms, frontend, without writing a single line of javascript

Parsley JavaScript form validation, without actually writing a single line of JavaScript! Version 2.9.2 Doc See index.html and doc/ Requirements jQuer

Guillaume Potier 9k Dec 27, 2022
The best @jquery plugin to validate form fields. Designed to use with Bootstrap + Zurb Foundation + Pure + SemanticUI + UIKit + Your own frameworks.

FormValidation - Download http://formvalidation.io - The best jQuery plugin to validate form fields, designed to use with: Bootstrap Foundation Pure S

FormValidation 2.8k Mar 29, 2021
[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.

jQuery Form Validator [DISCONTINUED] Validation framework that let's you configure, rather than code, your validation logic. I started writing this pl

Victor Jonsson 976 Dec 30, 2022
Validate properties and well known annotations in your Backstage catalog-info.yaml files.

Backstage entity validator This package can be used as a GitHub action or a standalone node.js module GitHub action Inputs path Optional Path to the c

Roadie 39 Dec 26, 2022
Validate for XML schema and returns all the possible failures

detailed-xml-validator Validate for XML schema and returns all the possible failures Sample Rules file <?xml version = "1.0"?> <students nillable="fa

Natural Intelligence 11 Dec 20, 2022
This Login Form made using React hooks , React Js , Css, Json. This form have 3 inputs, it also validate those inputs & it also having length limitations.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Yogesh Sharma 0 Jan 3, 2022
Validate graphql operations against a schema

@graphql-validate With the power of GraphQL-Tools and GraphQL-JS, we are able to provide a smooth experience for validation your GraphQL operations du

Saihajpreet Singh 13 Dec 23, 2022
Simple validator for Steuerliche Identifikationsnummer (German personal tax number) according to the official docs (see readme).

simple-de-taxid-validator Important Code of this validator is taken (with small changes like optimization or removing not needed elements) from THIS R

Wojciech 3 Feb 24, 2022