Skip to content

Commit ca96acb

Browse files
author
Esteban Frare
committed
feat(isTaxId): add tax id for Argentina, es-AR
1 parent 9ba1735 commit ca96acb

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Validator | Description
167167
**isSlug(str)** | check if the string is of type slug.
168168
**isStrongPassword(str [, options])** | check if the string can be considered a strong password or not. Allows for custom requirements or scoring rules. If `returnScore` is true, then the function returns an integer score for the password rather than a boolean.<br/>Default options: <br/>`{ minLength: 8, minLowercase: 1, minUppercase: 1, minNumbers: 1, minSymbols: 1, returnScore: false, pointsPerUnique: 1, pointsPerRepeat: 0.5, pointsForContainingLower: 10, pointsForContainingUpper: 10, pointsForContainingNumber: 10, pointsForContainingSymbol: 10 }`
169169
**isTime(str [, options])** | check if the string is a valid time e.g. [`23:01:59`, new Date().toLocaleTimeString()].<br/><br/> `options` is an object which can contain the keys `hourFormat` or `mode`.<br/><br/>`hourFormat` is a key and defaults to `'hour24'`.<br/><br/>`mode` is a key and defaults to `'default'`. <br/><br/>`hourFomat` can contain the values `'hour12'` or `'hour24'`, `'hour24'` will validate hours in 24 format and `'hour12'` will validate hours in 12 format. <br/><br/>`mode` can contain the values `'default'` or `'withSeconds'`, `'default'` will validate `HH:MM` format, `'withSeconds'` will validate the `HH:MM:SS` format.
170-
**isTaxID(str, locale)** | check if the string is a valid Tax Identification Number. Default locale is `en-US`.<br/><br/>More info about exact TIN support can be found in `src/lib/isTaxID.js`.<br/><br/>Supported locales: `[ 'bg-BG', 'cs-CZ', 'de-AT', 'de-DE', 'dk-DK', 'el-CY', 'el-GR', 'en-CA', 'en-GB', 'en-IE', 'en-US', 'es-ES', 'et-EE', 'fi-FI', 'fr-BE', 'fr-CA', 'fr-FR', 'fr-LU', 'hr-HR', 'hu-HU', 'it-IT', 'lb-LU', 'lt-LT', 'lv-LV', 'mt-MT', 'nl-BE', 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'sk-SK', 'sl-SI', 'sv-SE' ]`.
170+
**isTaxID(str, locale)** | check if the string is a valid Tax Identification Number. Default locale is `en-US`.<br/><br/>More info about exact TIN support can be found in `src/lib/isTaxID.js`.<br/><br/>Supported locales: `[ 'bg-BG', 'cs-CZ', 'de-AT', 'de-DE', 'dk-DK', 'el-CY', 'el-GR', 'en-CA', 'en-GB', 'en-IE', 'en-US', 'es-AR', 'es-ES', 'et-EE', 'fi-FI', 'fr-BE', 'fr-CA', 'fr-FR', 'fr-LU', 'hr-HR', 'hu-HU', 'it-IT', 'lb-LU', 'lt-LT', 'lv-LV', 'mt-MT', 'nl-BE', 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'sk-SK', 'sl-SI', 'sv-SE' ]`.
171171
**isURL(str [, options])** | check if the string is a URL.<br/><br/>`options` is an object which defaults to `{ protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, require_host: true, require_port: false, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, allow_fragments: true, allow_query_components: true, disallow_auth: false, validate_length: true }`.<br/><br/>`require_protocol` - if set to true isURL will return false if protocol is not present in the URL.<br/>`require_valid_protocol` - isURL will check if the URL's protocol is present in the protocols option.<br/>`protocols` - valid protocols can be modified with this option.<br/>`require_host` - if set to false isURL will not check if host is present in the URL.<br/>`require_port` - if set to true isURL will check if port is present in the URL.<br/>`allow_protocol_relative_urls` - if set to true protocol relative URLs will be allowed.<br/>`allow_fragments` - if set to false isURL will return false if fragments are present.<br/>`allow_query_components` - if set to false isURL will return false if query components are present.<br/>`validate_length` - if set to false isURL will skip string length validation (2083 characters is IE max URL length).
172172
**isUUID(str [, version])** | check if the string is a UUID (version 1, 2, 3, 4 or 5).
173173
**isVariableWidth(str)** | check if the string contains a mixture of full and half-width chars.

src/lib/isTaxID.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,30 @@ function enUsCheck(tin) {
376376
return enUsGetPrefixes().indexOf(tin.slice(0, 2)) !== -1;
377377
}
378378

379+
/*
380+
* es-AR validation function
381+
* Clave Única de Identificación Tributaria (CUIT/CUIL)
382+
* Sourced from:
383+
* - https://servicioscf.afip.gob.ar/publico/abc/ABCpaso2.aspx?id_nivel1=3036&id_nivel2=3040&p=Conceptos%20b%C3%A1sicos
384+
* - https://es.wikipedia.org/wiki/Clave_%C3%9Anica_de_Identificaci%C3%B3n_Tributaria
385+
*/
386+
387+
function esArCheck(tin) {
388+
let accum = 0;
389+
let digits = tin.split('');
390+
let digit = parseInt(digits.pop(), 10);
391+
for (let i = 0; i < digits.length; i++) {
392+
accum += digits[9 - i] * (2 + (i % 6));
393+
}
394+
let verif = 11 - (accum % 11);
395+
if (verif === 11) {
396+
verif = 0;
397+
} else if (verif === 10) {
398+
verif = 9;
399+
}
400+
return digit === verif;
401+
}
402+
379403
/*
380404
* es-ES validation function
381405
* (Documento Nacional de Identidad (DNI)
@@ -1137,6 +1161,7 @@ const taxIdFormat = {
11371161
'en-GB': /^\d{10}$|^(?!GB|NK|TN|ZZ)(?![DFIQUV])[A-Z](?![DFIQUVO])[A-Z]\d{6}[ABCD ]$/i,
11381162
'en-IE': /^\d{7}[A-W][A-IW]{0,1}$/i,
11391163
'en-US': /^\d{2}[- ]{0,1}\d{7}$/,
1164+
'es-AR': /(20|23|24|27|30|33|34)[0-9]{8}[0-9]/,
11401165
'es-ES': /^(\d{0,8}|[XYZKLM]\d{7})[A-HJ-NP-TV-Z]$/i,
11411166
'et-EE': /^[1-6]\d{6}(00[1-9]|0[1-9][0-9]|[1-6][0-9]{2}|70[0-9]|710)\d$/,
11421167
'fi-FI': /^\d{6}[-+A]\d{3}[0-9A-FHJ-NPR-Y]$/i,
@@ -1175,6 +1200,7 @@ const taxIdCheck = {
11751200
'en-CA': isCanadianSIN,
11761201
'en-IE': enIeCheck,
11771202
'en-US': enUsCheck,
1203+
'es-AR': esArCheck,
11781204
'es-ES': esEsCheck,
11791205
'et-EE': etEeCheck,
11801206
'fi-FI': fiFiCheck,

test/validators.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12321,6 +12321,25 @@ describe('Validators', () => {
1232112321
'28-1234567',
1232212322
'96-1234567'],
1232312323
});
12324+
test({
12325+
validator: 'isTaxID',
12326+
args: ['es-AR'],
12327+
valid: [
12328+
'20271633638',
12329+
'23274986069',
12330+
'27333234519',
12331+
'30678561165',
12332+
'33693450239',
12333+
'34557619099'],
12334+
invalid: [
12335+
'20-27163363-8',
12336+
'20.27163363.8',
12337+
'33693450231',
12338+
'69345023',
12339+
'693450233123123',
12340+
'3369ew50231',
12341+
'34557619095'],
12342+
});
1232412343
test({
1232512344
validator: 'isTaxID',
1232612345
args: ['es-ES'],

0 commit comments

Comments
 (0)