diff --git a/README.md b/README.md index 370efabd0..2ba0f623a 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ Validator | Description **isHexColor(str)** | check if the string is a hexadecimal color. **isHSL(str)** | check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).

Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: `hsl(200grad+.1%62%/1)`). **isIBAN(str)** | check if a string is a IBAN (International Bank Account Number). -**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'IN', 'NO', 'zh-TW', 'he-IL', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. +**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'IN', 'IT', 'NO', 'zh-TW', 'he-IL', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIMEI(str [, options]))** | check if the string is a valid IMEI number. Imei should be of format `###############` or `##-######-######-#`.

`options` is an object which can contain the keys `allow_hyphens`. Defaults to first format . If allow_hyphens is set to true, the validator will validate the second format. **isIn(str, values)** | check if the string is in a array of allowed values. **isInt(str [, options])** | check if the string is an integer.

`options` is an object which can contain the keys `min` and/or `max` to check the integer is within boundaries (e.g. `{ min: 10, max: 99 }`). `options` can also contain the key `allow_leading_zeroes`, which when set to false will disallow integer values with leading zeroes (e.g. `{ allow_leading_zeroes: false }`). Finally, `options` can contain the keys `gt` and/or `lt` which will enforce integers being greater than or less than, respectively, the value provided (e.g. `{gt: 1, lt: 4}` for a number between 1 and 4). diff --git a/lib/isIdentityCard.js b/lib/isIdentityCard.js index 7f5c63d5d..d2b89fd47 100644 --- a/lib/isIdentityCard.js +++ b/lib/isIdentityCard.js @@ -293,4 +293,4 @@ function isIdentityCard(str, locale) { } module.exports = exports.default; -module.exports.default = exports.default; \ No newline at end of file +module.exports.default = exports.default; diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index 4fc5c8385..cda258cfc 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -75,6 +75,11 @@ const validators = { return c === 0; }, + IT: function IT(str) { + if (str.length !== 9) return false; + if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana + return str.search(/C[A-Z]\d{5}[A-Z]{2}/is) > -1; + }, NO: (str) => { const sanitized = str.trim(); if (isNaN(Number(sanitized))) return false; diff --git a/test/validators.js b/test/validators.js index 824ee3302..5a90788e8 100755 --- a/test/validators.js +++ b/test/validators.js @@ -4086,7 +4086,8 @@ describe('Validators', () => { 'Y1234567B', 'Z1234567C', ], - }, { + }, + { locale: 'IN', valid: [ '298448863364', @@ -4102,6 +4103,19 @@ describe('Validators', () => { 'X1234567L', ], }, + { + locale: 'IT', + valid: [ + 'CR43675TM', + 'CA79382RA', + ], + invalid: [ + 'CA00000AA', + 'CB2342TG', + 'CS123456A', + 'C1236EC', + ], + }, { locale: 'NO', valid: [