diff --git a/README.md b/README.md index cc9a97882..ceb80c015 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ Validator | Description **isHexColor(str [, options])** | check if the string is a hexadecimal color.

`options` is an object that defaults to `{ require_hashtag: false }`.
Options:
`require_hashtag`: Enforce # prefix, default false. **isHSL(str)** | check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification][CSS Colors Level 4 Specification].

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

`options` is an object which accepts two attributes: `whitelist`: where you can restrict IBAN codes you want to receive data from and `blacklist`: where you can remove some of the countries from the current list. For both you can use an array with the following values `['AD','AE','AL','AT','AZ','BA','BE','BG','BH','BR','BY','CH','CR','CY','CZ','DE','DK','DO','EE','EG','ES','FI','FO','FR','GB','GE','GI','GL','GR','GT','HR','HU','IE','IL','IQ','IR','IS','IT','JO','KW','KZ','LB','LC','LI','LT','LU','LV','MC','MD','ME','MK','MR','MT','MU','MZ','NL','NO','PK','PL','PS','PT','QA','RO','RS','SA','SC','SE','SI','SK','SM','SV','TL','TN','TR','UA','VA','VG','XK']`. -**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['LK', 'PL', 'ES', 'FI', 'IN', 'IT', 'IR', 'MZ', 'NO', 'TH', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN', 'zh-HK', 'PK']` OR `'any'`. If 'any' is used, function will check if any of the locales match.

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

`locale` is one of `['LK', 'PL', 'ES', 'FI', 'IN', 'IT', 'IR', 'MZ', 'NL', 'NO', 'TH', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN', 'zh-HK', 'PK']` OR `'any'`. If 'any' is used, function will check if any of the locales match.

Defaults to 'any'. **isIMEI(str [, options]))** | check if the string is a valid [IMEI number][IMEI]. 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 an 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/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index fc37d4a29..f465d8b37 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -153,6 +153,23 @@ const validators = { 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; }, + NL: (str) => { + if (!/^\d{8,9}$/.test(str)) return false; + + str = `0${str}`.slice(-9); + + let sum = 0; + + for (let i = 0; i < 9; i++) { + if (i === 8) { + sum += str[i] * -1; + } else { + sum += str[i] * (9 - i); + } + } + + return !(sum % 11); + }, NO: (str) => { const sanitized = str.trim(); if (isNaN(Number(sanitized))) return false; diff --git a/test/validators.test.js b/test/validators.test.js index 60ffa9c81..eeb3129a4 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -6844,6 +6844,38 @@ describe('Validators', () => { 'C1236EC', ], }, + { + locale: 'NL', + valid: [ + '34074193', + '075755828', + '143065877', + '282553162', + '306255030', + '478764704', + '569449972', + '661758977', + '770949411', + '801459904', + '942614070', + ], + invalid: [ + 'abc', + '123', + '99999999999', + '12474588', + '062996534', + '100563191', + '245999283', + '375004177', + '452414405', + '591587198', + '638616545', + '773589513', + '807465789', + '930304232', + ], + }, { locale: 'NO', valid: [