Repository: validatorjs/validator.js
Pull request #1112 (2019-09-24 15:03:40)

added support for Tunisia National Identity Card
test Successfully passed
```batch
yarn clean.win
yarn run v1.17.3
$ yarn clean:node.win && yarn clean:browser.win
$ RMDIR /S /Q lib && ERASE /F /Q index.js
$ ERASE /F /Q validator*.js
Done in 1.76s.

yarn buildtest
yarn run v1.17.3
$ yarn build && yarn lint:fix && yarn test
$ yarn build:browser && yarn build:node
$ node --require @babel/register build-browser && yarn minify
$ uglifyjs validator.js -o validator.min.js  --compress --mangle --comments /Copyright/
$ babel src -d .
Successfully compiled 80 files with Babel.
$ eslint --fix src test
$ yarn lint && yarn build
$ eslint src test
$ yarn build:browser && yarn build:node
$ node --require @babel/register build-browser && yarn minify
$ uglifyjs validator.js -o validator.min.js  --compress --mangle --comments /Copyright/
$ babel src -d .
Successfully compiled 80 files with Babel.
$ nyc mocha --require @babel/register --reporter dot


  ..........................................................................................
  .......................................................................

  161 passing (362ms)


=============================== Coverage summary ===============================
Statements   : 100% ( 1017/1017 )
Branches     : 100% ( 632/632 )
Functions    : 100% ( 96/96 )
Lines        : 100% ( 986/986 )
================================================================================
Done in 64.79s.

```

profnandaa: @CodeIter -- just the merge conflicts and we are good. Thanks and welcome to contributors! 🎉
profnandaa: ping @CodeIter 
/cc. @tux-tn 

Patch:
diff --git a/README.md b/README.md
index 239b3a8..d19ec3b 100644
--- a/README.md
+++ b/README.md
@@ -112,7 +112,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).<br/><br/>Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: `hsl(200grad+.1%62%/1)`).
 **isRgbColor(str, [, includePercentValues])**                     | check if the string is a rgb or rgba color.<br/><br/>`includePercentValues` defaults to `true`. If you don't want to allow to set `rgb` or `rgba` values with percents, like `rgb(5%,5%,5%)`, or `rgba(90%,90%,90%,.3)`, then set it to false.
-**isIdentityCard(str [, locale])**      | check if the string is a valid identity card code.<br/><br/>`locale` is one of `['ES', 'zh-TW', 'he-IL']` OR `'any'`. If 'any' is used, function will check if any of the locals match.<br/><br/>Defaults to 'any'.
+**isIdentityCard(str [, locale])**      | check if the string is a valid identity card code.<br/><br/>`locale` is one of `['ES', 'zh-TW', 'he-IL', 'ar-TN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.<br/><br/>Defaults to 'any'.
 **isIn(str, values)**                   | check if the string is in a array of allowed values.
 **isInt(str [, options])**              | check if the string is an integer.<br/><br/>`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).
 **isIP(str [, version])**               | check if the string is an IP (version 4 or 6).
diff --git a/package.json b/package.json
index b9d0f46..ef9a803 100644
--- a/package.json
+++ b/package.json
@@ -50,6 +50,7 @@
     "eslint-plugin-import": "^2.11.0",
     "mocha": "^5.1.1",
     "nyc": "^14.1.0",
+    "rimraf": "^3.0.0",
     "rollup": "^0.43.0",
     "rollup-plugin-babel": "^4.0.1",
     "uglify-js": "^3.0.19"
@@ -57,9 +58,9 @@
   "scripts": {
     "lint": "eslint src test",
     "lint:fix": "eslint --fix src test",
-    "clean:node": "rm -rf index.js lib",
-    "clean:es": "rm -rf es",
-    "clean:browser": "rm -rf validator*.js",
+    "clean:node": "rimraf index.js lib",
+    "clean:es": "rimraf es",
+    "clean:browser": "rimraf validator*.js",
     "clean": "npm run clean:node && npm run clean:browser && npm run clean:es",
     "minify": "uglifyjs validator.js -o validator.min.js  --compress --mangle --comments /Copyright/",
     "build:browser": "node --require @babel/register build-browser && npm run minify",
diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js
index c74acde..6e7d29a 100644
--- a/src/lib/isIdentityCard.js
+++ b/src/lib/isIdentityCard.js
@@ -51,6 +51,18 @@ const validators = {
     }
     return sum % 10 === 0;
   },
+  'ar-TN': (str) => {
+    const DNI = /^\d{8}$/;
+
+    // sanitize user input
+    const sanitized = str.trim();
+
+    // validate the data structure
+    if (!DNI.test(sanitized)) {
+      return false;
+    }
+    return true;
+  },
   'zh-TW': (str) => {
     const ALPHABET_CODES = {
       A: 10,


Test patch:
diff --git a/test/validators.js b/test/validators.js
index 2a76438..7b82560 100644
--- a/test/validators.js
+++ b/test/validators.js
@@ -3977,6 +3977,35 @@ describe('Validators', () => {
           '336000842',
         ],
       },
+      {
+        locale: 'ar-TN',
+        valid: [
+          '09958092',
+          '09151092',
+          '65126506',
+          '79378815',
+          '58994407',
+          '73089789',
+          '73260311',
+        ],
+        invalid: [
+          '123456789546',
+          '123456789',
+          '023456789',
+          '12345678A',
+          '12345',
+          '1234578A',
+          '123 578A',
+          '12345 678Z',
+          '12345678-Z',
+          '1234*6789',
+          '1234*678Z',
+          'GE9800as98',
+          'X231071922',
+          '1234*678Z',
+          '12345678!',
+        ],
+      },
       {
         locale: 'zh-TW',
         valid: [