diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index bf7c05a0e..86301ef81 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -9,4 +9,4 @@ feat(validatorName): brief title of what has been done - [ ] PR contains only changes related; no stray files, etc. - [ ] README updated (where applicable) -- [ ] Tests written (where applicable) +- [ ] Tests written (where applicable) \ No newline at end of file diff --git a/README.md b/README.md index 25af675ed..c1d04439c 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,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', 'IT', 'IR', 'MZ', 'NO', 'TH', 'zh-TW', 'he-IL', 'ar-LY', '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 `['Aadhar','ES', 'IN', 'IT', 'IR', 'MZ', 'NO', 'TH', 'zh-TW', 'he-IL', 'ar-LY', '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/package.json b/package.json index b02fd04a2..3056b48f0 100644 --- a/package.json +++ b/package.json @@ -71,4 +71,4 @@ "node": ">= 0.10" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/src/index.js b/src/index.js index 59b813c1f..ebf4257e3 100644 --- a/src/index.js +++ b/src/index.js @@ -223,6 +223,7 @@ const validator = { isLicensePlate, isVAT, ibanLocales, + }; export default validator; diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index 64616340b..b4198f2c1 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -1,6 +1,20 @@ import assertString from './util/assertString'; const validators = { + Aadhar: (str) => { + const aadhar = str; + const adharcardTwelveDigit = /^\d{12}$/; + const adharSixteenDigit = /^\d{16}$/; + if (aadhar !== '') { + if (aadhar.match(adharcardTwelveDigit)) { + return true; + } else if (aadhar.match(adharSixteenDigit)) { + return true; + } return false; + } + return false; + }, + ES: (str) => { assertString(str); diff --git a/test/client-side.js b/test/client-side.js index f0b5ca72c..58fcf576b 100644 --- a/test/client-side.js +++ b/test/client-side.js @@ -22,7 +22,10 @@ describe('Minified version', () => { assert.strictEqual(min.isEmail('foo@bar.com'), true); assert.strictEqual(min.isEmail('foo'), false); }); - + it('should validate strings', () => { + assert.strictEqual(validator.isIdentityCard('820315678934', 'Aadhar'), true); + assert.strictEqual(validator.isIdentityCard('63789', 'Aadhar'), false); + }); it('should sanitize strings', () => { assert.strictEqual(min.toBoolean('1'), true); }); diff --git a/test/validators.js b/test/validators.js index 6bb607282..cdb84264c 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4860,6 +4860,25 @@ describe('Validators', () => { '336000842', ], }, + { + locale: 'Aadhar', + valid: [ + '789067894567', + '236757897890', + '768956789045', + '567890457894', + '456789546754', + ], + invalid: [ + '123456789', + 'A185034995', + 'X431071923', + 'GE9800as98', + 'X231071922', + '1234*678Z', + '0123456895', + ], + }, ]; let allValid = [];