Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for Tunisia National Identity Card #1112

Merged
merged 4 commits into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@
"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"
},
"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",
Expand Down
12 changes: 12 additions & 0 deletions src/lib/isIdentityCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 29 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down