Giter Club home page Giter Club logo

clabe-validator's Introduction

CLABE Validator

logo

JavaScript library to analyze or create a CLABE number for a Mexican bank account

License:MIT npm Dependencies Vulnerabilities Hits Build

CLABE (Clave Bancaria Estandarizada — Spanish for "standardized banking code") is a banking standard from the Mexican Bank Association (Asociación de Bancos de México — ABM) for uniform numbering of bank accounts.  CLABE numbers are 18 digits long.  See: https://en.wikipedia.org/wiki/CLABE

A) Online form

Try it out:
https://centerkey.com/clabe

B) Setup

Browser

Include in a web page:

<script src=clabe.min.js></script>

or from the jsdelivr.com CDN:

<script src=https://cdn.jsdelivr.net/npm/[email protected]/dist/clabe.min.js></script>

node

Install package:

$ npm install clabe-validator

Import package:

const clabe = require('clabe-validator');

C) Validator usage

Pass the CLABE number as an 18-character string into clabe.validate(clabeNum).

1. Example JavaScript code

const clabeNum = '002010077777777771';
const clabeCheck = clabe.validate(clabeNum);
console.log(clabeCheck.ok ? '¡Que bueno!' : '¡Muy mal!');
console.log('Your bank: ' + clabeCheck.bank);

2. Example JSON result for a valid CLABE number

{
   ok:       true,
   error:    null,
   formatOk: true,
   tag:      'BANAMEX',
   bank:     'Banco Nacional de México, S.A.',
   city:     'Aguascalientes',
   account:  '07777777777'
}

3. Example JSON result for an invalid CLABE number

{
   ok:       false,
   formatOk: true,
   error:    'invalid-city',
   message:  'Invalid city code: 000'
}

The formatOk field indicates if the CLABE's length and checksum are both valid (even if the bank code or city code are invalid).

4. Possible errors

Error code Error message Format Ok
invalid-length Must be exactly 18 digits long false
invalid-characters Must be only numeric digits (no letters) false
invalid-checksum Invalid checksum, last digit should be: [DIGIT] false
invalid-bank Invalid bank code: [CODE] true
invalid-city Invalid city code: [CODE] true

D) Calculator usage

Pass the bank code, city code, and account number into clabe.calculate(bankCode, cityCode, accountNumber) and get the 18-character CLABE number back.

const clabeNum = clabe.calculate(2, 10, 7777777777);
console.log(clabeNum === '002010077777777771');  //true

E) Notes

  1. Feel free to submit questions at: github.com/center-key/clabe-validator/issues
  2. To be a contributor, fork the project and run the commands npm install and npm test on your local clone.  Make your edits and rerun the tests.  Pull requests welcome (no need to update the version in package.json or any files in the dist folder as they are all updated as part of the release process).

CLABE Validator code is open source under the MIT License, and the documentation is published under the CC BY-SA 4.0 license.

clabe-validator's People

Contributors

dpilafian avatar notunderground avatar chrishenx avatar lalomts avatar shethkushal avatar aespinosa-lj avatar calvinsettachatgul avatar nushio avatar

Watchers

James Cloos avatar

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.