Skip to content

Commit

Permalink
Add option to validate CCC and Institution name (#2)
Browse files Browse the repository at this point in the history
* Add option to validate CCC and Institution name

* Upgrade package version
  • Loading branch information
JuanMaRuiz committed Sep 19, 2020
1 parent 2c0daaa commit 1222a91
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
## [1.1.0] - 2020-08-26
### Add options param
* Add the possibility to pass an options object with the institution name. Validator will check the correctness of the ccc number and if
the institution name matched with the passed ccc.

## [1.0.0] - 2020-08-26
### First util version
* Add first validator version for Spain bank account
51 changes: 42 additions & 9 deletions README.md
Expand Up @@ -5,18 +5,23 @@

This module provide a `validate` method to check if the given CCC is valid or not.

| Option | Type | Required | Description |
|-------------|-----------|----------|----------|
| ccc | `String` | `true` | |
| options | `Object` | `false` | Option available: `institution`|


**Note**

Due the different logic to validate bank account depending on the Country. This validator is only valid for **Spain** bank accounts. If you are interested in this validator and you want to add a new country, you can:

* **Open an issue like this:**

```
Title: Add support for new Country
* **Country**: _New country_
* **Validation**: _Link to info about how to validade the account_
```
> Title: Add support for new Country
>
> * **Country**: _New country_
> * **Validation**: _Link to info about how to validade the account_
> * **List with entinty codes for banks**: _Link or file which contains a list with all the banks and entity codes_
* **Open a Pull request** adding your own validation.

Expand All @@ -28,18 +33,46 @@ npm i ccc-util --save-dev

## Usage

### Passing only a CCC
```bash
const { validate } = require('ccc-util');

validate('14650100971716610913'); //=> true
validate('14650100-97-1716610913'); //=> true
validate('14650100 97 1716610913'); //=> true
validate('0144 9181 1115 8790 3375'); //=> true
validate('0144-9181-1115-8790-3375'); //=> true
validate(' 0144 -9181-1115-8790-3375'); //=> true

validate('0137081073'); //=> false

validate('0049-1500-05-1234567890'); //=> false
```
### Passing CCC and institution name
```bash
const { validate } = require('ccc-util');

validate('0144 9181 1115 8790 3375', { institution: 'BNP Paribas Securities Services, S.E.') //=> true
validate('0144 9181 1115 8790 3375', { institution: 'BNP Paribas Securities Services') //=> flase
```
### Codes of banking entities in Spain
Passing `institution: 'Name of Institution'` to `ccc-util` will validate the bank account number and the entity number (first four numbers of CCC).
In the list below you will find some of the codes of monetary financial institutions of Spain. You can find all of them in **[Banco de España official's page](https://www.bde.es/webbde/es/estadis/ifm/if_es.html)**
| Entity Code | Bank Name |
|-------------|-----------|
| ES0049 | Banco Santander, S.A.|
| ES2038 | Bankia, S.A.|
| ES8832 | Bankinter Consumer Finance, E.F.C., S.A.|
| ES0128 | Bankinter, S.A.|
| ES2100 | CaixaBank, S.A.|
| ES1465 | ING Bank, N.V. S.E|
| ES2095 | Kutxabank, S.A.|
| ES2048 | Liberbank, S.A.|
| ES0073 | Open Bank, S.A.|
### Reference
* [How to validate an Spanish CCC](https://es.wikipedia.org/wiki/Código_cuenta_cliente#D%C3%ADgitos_de_control)
23 changes: 17 additions & 6 deletions __test__/validator.test.js
@@ -1,13 +1,24 @@
const validate = require('./../src/validator.js');

test('it should return TRUE if the passed value is a valid CCC', () => {
expect(validate('14650100971716610913')).toBe(true);
expect(validate('14650100 97 1716610913')).toBe(true);
expect(validate('14650100-97-1716610913')).toBe(true);
expect(validate('14650100- 97-17166 10913')).toBe(true);
expect(validate('0144 9181 1115 8790 3375')).toBe(true);
expect(validate('0144 91811115 87903375')).toBe(true);
expect(validate('0144-9181-1115-8790-3375')).toBe(true);
expect(validate('0144 -9181- 1115- 8790-3375')).toBe(true);
});

test('should return FALSE if the passed value is not a valid CCC', () => {
expect(validate('1465010097171661913')).toBe(false);
test('it should return FALSE if the passed value is not a valid CCC', () => {
expect(validate('7220199120124205847470')).toBe(false);
expect(validate('0049-1500-05-1234567890')).toBe(false);
});

test('it should throw an error when the "institution" option is not a string', () => {
expect( () => validate('7220199120124205847470', { institution: 2})).toThrow('Institution is not a valid string');
expect( () => validate('7220199120124205847470', { institution: []})).toThrow('Institution is not a valid string');
expect( () => validate('7220199120124205847470', { institution: true})).toThrow('Institution is not a valid string');
expect( () => validate('7220199120124205847470', { institution: {}})).toThrow('Institution is not a valid string');
});

test('it return TRUE when passed insitution code and codeEntity value matches', () => {
expect(validate('0144 9181 1115 8790 3375', { institution: 'BNP Paribas Securities Services, S.E.'})).toBe(true);
});
12 changes: 9 additions & 3 deletions package.json
@@ -1,10 +1,11 @@
{
"name": "ccc-util",
"version": "1.0.2",
"version": "1.1.0",
"description": "Util to validate CCC code. It also can be used to generate a valid CCC for testing purposes",
"main": "index.js",
"scripts": {
"test": "jest --coverage"
"test": "jest --coverage",
"lint": "eslint ."
},
"keywords": [
"ccc",
Expand All @@ -18,5 +19,10 @@
"coveralls": "^3.1.0",
"eslint": "^7.8.1",
"jest": "^26.4.2"
}
},
"repository": {
"type": "git",
"url": "https://github.com/JuanMaRuiz/ccc-util.git"
},
"homepage": "https://github.com/JuanMaRuiz/ccc-util"
}
251 changes: 251 additions & 0 deletions src/es-institution-list.js
@@ -0,0 +1,251 @@
module.exports = {
'ES0241': 'A&G Banca Privada, S.A.',
'ES2080': 'Abanca Corporación Bancaria, S.A.',
'ES8620': 'Abanca Servicios Financieros E.F.C., S.A.',
'ES1535': 'AKF Bank Gmbh & Co Kg, S.E.',
'ES0011': 'Allfunds Bank, S.A',
'ES1544': 'Andbank España, S.A.',
'ES0136': 'Aresbank, S.A.',
'ES3183': 'Arquia Bank, S.A.',
'ES1541': 'Attijariwafa Bank Europe, S.E',
'ES1554': 'Banca Farmafactoring, SPA Suc en España',
'ES0061': 'Banca March, S.A.',
'ES1550': 'Banca Popolare Etica Sociedad Cooperativa Per Aziones, S.E.',
'ES0078': 'Banca Pueyo, S.A.',
'ES0188': 'Banco Alcalá, S.A.',
'ES0182': 'Banco Bilbao Vizcaya Argentaria, S.A.',
'ES0234': 'Banco Caminos, S.A.',
'ES0225': 'Banco Cetelem, S.A.',
'ES0198': 'Banco Cooperativo Español, S.A.',
'ES0091': 'Banco de Albacete, S.A.',
'ES0240': 'Banco de Crédito Social Cooperativo, S.A.',
'ES0003': 'Banco de Depósitos, S.A.',
'ES9000': 'Banco de España',
'ES1569': 'Banco de Investimento Global S.A., S.E.',
'ES0169': 'Banco de la Nación Argentina, S.E.',
'ES0081': 'Banco de Sabadell, S.A.',
'ES0155': 'Banco do Brasil, AG., S.E',
'ES0184': 'Banco Europeo de Finanzas, S.A.',
'ES0220': 'Banco Finantia Spain, S.A.',
'ES0113': 'Banco Industrial de Bilbao, S.A.',
'ES0232': 'Banco Inversis, S.A.',
'ES0186': 'Banco Mediolanum, S.A.',
'ES0121': 'Banco Occidental, S.A.',
'ES0235': 'Banco Pichincha España, S.A.',
'ES1509': 'Banco Primus, S.A., S.E.',
'ES0049': 'Banco Santander, S.A.',
'ES0125': 'Bancofar, S.A.',
'ES0200': 'Bank Degroof Petercam Spain, S.A.',
'ES1485': 'Bank of America Merrill Lynch International DAC, Sucursal en España',
'ES2038': 'Bankia, S.A.',
'ES8832': 'Bankinter Consumer Finance, E.F.C., S.A.',
'ES0128': 'Bankinter, S.A.',
'ES0138': 'Bankoa, S.A.',
'ES1525': 'Banque Chaabi Du Maroc, S.E.',
'ES8211': 'Bansabadell Financiación E.F.C., S.A.',
'ES0152': 'Barclays Bank Ireland Plc, S.E.',
'ES8235': 'Bilbao Hipotecaria, S.A., E.F.C.',
'ES1521': 'Binckbank NV, S.E.',
'ESA86969607': 'BIP&Drive EDE, S.A',
'ES0219': 'BMCE Bank International, S.A.',
'ES1533': 'BMW Bank GMBH, SE',
'ES6717': 'Bnext Electronic Issuer, E.D.E. S.L.',
'ES1532': 'BNP Paribas Factor, S.A., S.E.',
'ES0167': 'BNP Paribas Fortis, S.A., N.V., Sucursal en España',
'ES1492': 'BNP Paribas Lease Group, S.A., S.E.',
'ES0144': 'BNP Paribas Securities Services, S.E.',
'ES0149': 'BNP Paribas, S.E.',
'ES1500': 'BPCE Lease, S.A., S.E.',
'ES3060': 'C.R. Burgos, Fuentepelayo, Segovia Y Castelldans, S.C.C.',
'ES3190': 'C.R. de Albacete, Ciudad Real Y Cuenca, S.C.C.',
'ES1545': 'CA Indosuez Wealth (Europe), S.E.',
'ES0038': 'CACEIS Bank Spain, S.A.',
'ESA88147053': 'CACF Bankia Consumer Finance EFC, S.A',
'ES1451': 'Caisse Régionale Crédit Agricole Mutuel Sud Med, S.E.',
'ES1493': 'Caixa Banco de Investimento, S.A., S.E.',
'ES3025': 'Caixa de C. dels Enginyers-C.C. Ingenieros S.C.C.',
'ES3159': 'Caixa Popular-Caixa Rural, S.C.C.V.',
'ES3045': 'Caixa R. Altea, C.C.V.',
'ES3162': 'Caixa R. Benicarló, S.C.C.V.',
'ES3117': 'Caixa R. D\'Algemesí, S.C.V.C.',
'ES3105': 'Caixa R. de Callosa d\'en Sarrià, C.C.V.',
'ES3096': 'Caixa R. de L\'Alcudia, S.C.V.C.',
'ES3123': 'Caixa R. de Turis, C.C.V.',
'ES3070': 'Caixa R. Galega, S.C.C.L.G.',
'ES3111': 'Caixa R. La Vall S. Isidro, S.C.C.V.',
'ES3166': 'Caixa R. Les Coves de Vinroma, S.C.C.V.',
'ES3102': 'Caixa R. S. Vicent Ferrer de la Vall d\'Uixó, C.C.V.',
'ES3160': 'Caixa R. Sant Josep de Vilavella, S.C.C.V',
'ES3174': 'Caixa R. Vinaros, S.C.C.V.',
'ES3118': 'Caixa Rural Torrent, C.C.V.',
'ES6702': 'Caixabank Electronic Money, EDE, S.L.',
'ESV63050835': 'Caixabank Monetario Rendimiento, FI',
'ES8776': 'Caixabank Payments & Consumer, E.F.C., E.P., S.A.',
'ES2100': 'CaixaBank, S.A.',
'ES2045': 'Caja de Ahorros y M.P. de Ontinyent',
'ES3029': 'Caja de Crédito de Petrel, Caja Rural, C.C.V.',
'ES3035': 'Caja Laboral Popular, C.C.',
'ES3110': 'Caja R. Católico Agraria, S.C.C.V.',
'ES3005': 'Caja R. Central, S.C.C.',
'ES3150': 'Caja R. de Albal, C.C.V.',
'ES3179': 'Caja R. de Alginet, S.C.C.V.',
'ES3001': 'Caja R. de Almendralejo, S.C.C.',
'ES3059': 'Caja R. de Asturias, S.C.C.',
'ES3089': 'Caja R. de Baena Ntra. Sra. de Guadalupe, S.C.C.A.',
'ES3104': 'Caja R. de Cañete de las Torres Ntra. Sra. del Campo S.C.A.C.',
'ES3127': 'Caja R. de Casas Ibañez, S.C.C.Castilla-La Mancha',
'ES3121': 'Caja R. de Cheste, S.C.C.',
'ES3009': 'Caja R. de Extremadura, S.C.C.',
'ES3023': 'Caja R. de Granada, S.C.C.',
'ES3140': 'Caja R. de Guissona, S.C.C.',
'ES3067': 'Caja R. de Jaén, Barcelona y Madrid, S.C.C.',
'ES3008': 'Caja R. de Navarra, S.C.C.',
'ES3016': 'Caja R. de Salamanca, S.C.C.',
'ES3017': 'Caja R. de Soria, S.C.C.',
'ES3080': 'Caja R. de Teruel, S.C.C.',
'ES3020': 'Caja R. de Utrera, S.C.A.C.',
'ES3144': 'Caja R. de Villamalea, S.C.C.A. de Castilla la Mancha',
'ES3152': 'Caja R. de Villar, C.C.V.',
'ES3085': 'Caja R. de Zamora, C.C.',
'ES3187': 'Caja R. del Sur, S.C.C.',
'ES3157': 'Caja R. la Junquera de Chilches, S.C.C.V.',
'ES3134': 'Caja R. Ntra. Sra. la Esperanza de Onda, S.C.C.V.',
'ES3115': 'Caja R. Nuestra Madre del Sol, S.C.A.C.',
'ES3165': 'Caja R. S. Isidro de Vilafames, S.C.C.V.',
'ES3119': 'Caja R. S. Jaime de Alquerías Niño Perdido, S.C.C.V.',
'ES3113': 'Caja R. S. José de Alcora, S.C.C.V.',
'ES3130': 'Caja R. S. José de Almassora, S.C.C.V.',
'ES3112': 'Caja R. S. José de Burriana, S.C.C.V.',
'ES3135': 'Caja R. S. José de Nules, S.C.C.V.',
'ES3095': 'Caja R. S. Roque de Almenara S.C.C.V.',
'ES3018': 'Caja R.R.S. Agustín Fuente Álamo Murcia, S.C.C.',
'ES3191': 'Caja Rural de Aragon Soc. Coop. de Credito',
'ES3007': 'Caja Rural de Gijón, S.C. Asturiana de Crédito',
'ES3098': 'Caja Rural de Nueva Carteya, Sociedad Cooperativa Andaluza de Crédito',
'ES3058': 'Cajamar Caja Rural, S.C.C.',
'ES3076': 'Cajasiete, Caja Rural, S.C.C.',
'ES0237': 'Cajasur Banco, S.A',
'ES4706': 'Caterpillar Financial Corporación Financiera, S.A., E.F.C.',
'ES2000': 'Cecabank, S.A.',
'ES1553': 'China Construction Bank (Europe) S.A., S.E',
'ES1474': 'Citibank Europe PLC, S.E.',
'ES1499': 'Claas Financial Services, S.A.S., S.E.',
'ES1514': 'CNH Industrial Financial Services, S.E.',
'ES1546': 'CNH Capital Europe, S.A.S., S.E.',
'ES1543': 'Cofidis, S.A., S.E.',
'ES2056': 'Colonya - Caixa D\'Estalvis de Pollensa',
'ES0159': 'Commerzbank Aktiengesellschaft, S.E.',
'ES1459': 'Cooperatieve Rabobank U.A. S.E.',
'ES8221': 'Corporación Hipotecaria Mutual, S.A., E.F.C.',
'ES0154': 'Credit Agricole Corporate and Investment Bank , S.E.',
'ES1472': 'Credit Agricole Leasing & Factoring, S.E.',
'ES1555': 'Credit Mutuel Leasing, S.E',
'ES1460': 'Crédit Suisse AG, S.E.',
'ES1531': 'Credit Suisse International,S.E.',
'ES6711': 'Currencies Direct Limited, S.E',
'ES6716': 'Currencies Direct Spain, EDE, SL',
'ES1457': 'De Lage Landen International B.V., S.E.',
'ES1548': 'Dell Bank International Designated Activity Company, S.E.',
'ES0145': 'Deutsche Bank A.G., S.E.',
'ES0019': 'Deutsche Bank, S.A.E.',
'ES8826': 'Deutsche Leasing Iberica, E.F.C., S.A.',
'ES1501': 'Deutsche Pfandbriefbank Ag, S.E',
'ES6704': 'E. Kuantia EDE, S.L.',
'ES0211': 'EBN Banco de Negocios, S.A.',
'ES6710': 'Ebury Partners U.K., S.E',
'ES1473': 'Edmond de Rothschild (Europe), S.E.',
'ES1512': 'Elavon Financial Services Limited Designated Activity Company, S.E.',
'ES8321': 'Entre2 Servicios Financieros, E.F.C., S.A.',
'ESW8267529I': 'EURO EXCHANGE SECURITIES UK LIMITED, S.E.',
'ES3081': 'Eurocaja Rural, Sociedad Cooperativa de Crédito',
'ES6703': 'Euronet 360 Finance Limited, S.E.',
'ES0239': 'Evo Banco S.A.',
'ES8640': 'FCA Capital España, EFC SA',
'ES0218': 'Fce Bank plc S.E.',
'ES8308': 'Financiera Carrión, S.A., E.F.C.',
'ES8805': 'Financiera El Corte Inglés E.F.C., S.A.',
'ES8823': 'Financiera española de crédito a distancia, E.F.C., S.A.',
'ES6718': 'FINPAY Entidad de Dineero Electrónico, S.A',
'ES6714': 'Foreign Currency Direct PLC, S.E',
'ES8839': 'GCC Consumo, EFC',
'ES1496': 'Genefim, S.E.',
'ES1564': 'Goldman Sachs Bank Europe, SE',
'ES1497': 'Haitong Bank, S.A., S.E.',
'ES1504': 'Honda Bank GMBH, S.E.',
'ES0162': 'HSBC France, S.E.',
'ES2085': 'Ibercaja Banco, S.A.',
'ES4832': 'Ibercaja Leasing y Financiación, S.A., E.F.C.',
'ES1538': 'Industrial and Commercial Bank of China (Europe),S.A.,S.E.',
'ES1465': 'ING Bank, N.V. S.E',
'ES1000': 'Instituto de Crédito Oficial',
'ES1494': 'Intesa Sanpaolo S.P.A., S.E.',
'ES1516': 'J.P. Morgan Bank Luxembourg S.A., S.E.',
'ES1542': 'J.P. Morgan Securities Plc, S.E.',
'ES1482': 'John Deere Bank, S.A., S.E',
'ES1567': 'JP Morgan AG, S.E.',
'ES0151': 'Jpmorgan Chase Bank National Association, S.E.',
'ES2095': 'Kutxabank, S.A.',
'ES2048': 'Liberbank, S.A.',
'ES1547': 'Lombard Odier (Europe), S.A., S.E.',
'ES8342': 'Luzaro E.F.C. S.A',
'ES1520': 'Mediobanca, S.E.',
'ES1523': 'Mercedes-Benz Bank AG, S.E.',
'ES4799': 'Mercedes-Benz Financial Services España E.F.C., S.A.',
'ES1552': 'Mirabaud & CIE (Europe), S.A., S.E.',
'ES1559': 'Mizuho Bank Europe N.V., S.E.',
'ES0160': 'MUFG Bank (Europe) N.V., S.E.',
'ESV85567659': 'Mutuafondo Dinero, FI',
'ES1563': 'N26 Bank GmbH',
'ES1479': 'Natixis, S.A., S.E.',
'ES1566': 'Natwest Markets N.V., S.E',
'ES0131': 'Novo Banco, S.A., S.E.',
'ES0133': 'Nuevo Micro Bank, S.A',
'ES8814': 'Oney Servicios Financieros, E.F.C., S.A.',
'ES1571': 'Opel Bank, S.A., SE',
'ES0073': 'Open Bank, S.A.',
'ES1568': 'Orange Bank S.A., S.E.',
'ES6707': 'Pecunia Cards E.D.E. S.L',
'ES1488': 'Pictet & Cie (Europe), S.A., S.E.',
'ES6713': 'Prepaid Financial Services Limited, S.E',
'ES8838': 'PSA Financial Services Spain E.F.C. S.A',
'ES1534': 'Quintet Private Bank (Europe) S.A.,S.E.',
'ES1558': 'RBC EUROPE LIMITED, SUCURSAL EN ESPAÑA',
'ES1508': 'RCI Banque, S.A., S.E.',
'ES0083': 'RENTA 4 Banco, S.A.',
'ES3138': 'Ruralnostra, Sociedad Cooperativa de crédito Valenciana',
'ES0242': 'Sabadell Consumer Finance, S.A.',
'ES8835': 'Santander Brasil, E.F.C., S.A.',
'ES0224': 'Santander Consumer Finance, S.A.',
'ES8236': 'Santander Consumer, E.F.C., S.A.',
'ES8906': 'Santander Factoring y Confirming, S.A., E.F.C.',
'ES0036': 'Santander Investment, S.A.',
'ES4797': 'Santander Lease, S.A. EFC',
'ES8813': 'Scania Finance Hispania, E.F.C., S.A.',
'ES6705': 'SEFIDE, E.D.E. S.L.',
'ES8795': 'Servicios Financieros Carrefour, E.F.C., S.A.',
'ES8833': 'SG Equipment Finance Iberia, E.F.C., S.A.',
'ES1490': 'Singular Bank, S.A.',
'ES1551': 'SMBC Bank EU AG, S.E.',
'ES8816': 'Sociedad Conjunta para la Emisión y Gestión de Medios de Pago, E.F.C., S.A',
'ES0108': 'Société Genérale, S.E.',
'ES0216': 'Targobank, S.A.',
'ES8836': 'Telefonica Consumer Finance, EFC, S.A.',
'ES1570': 'The Governor and Company of the Bank of Ireland, S.E.',
'ES1487': 'Toyota Kreditbank GMBH, S.E.',
'ES4784': 'Transolver Finance, E.F.C., S.A.',
'ES1491': 'Triodos Bank, N.V., S.E.',
'ES0226': 'UBS Europe SE, S.E.',
'ES2103': 'Unicaja Banco, S.A.',
'ES1557': 'Unicredit. S.P.A. S.E',
'ES8596': 'Unión Cto. Fin. Mob. e Inm., Credifimo, E.F.C., S.A.',
'ES8512': 'Unión de Créditos Inmobiliarios, S.A., E.F.C.',
'ES8769': 'Unión Financiera Asturiana, S.A., E.F.C.',
'ES6719': 'UNNAX REGULATORY SERVICES, EDE, SL',
'ES6709': 'Up Aganea EDE, SA',
'ES8806': 'VFS Financial Services Spain E.F.C., S.A.',
'ES6715': 'Viva Payment Services, S.A. S.E.',
'ES1480': 'Volkswagen Bank GmbH, S.E.',
'ES0229': 'Wizink Bank, S.A.',
'ES8840': 'Xfera Consumer Finance, E.F.C. S.A.',
'ES1560': 'Younited, S.E.'
};

0 comments on commit 1222a91

Please sign in to comment.