Skip to content

Commit dac5814

Browse files
nimanthadilztux-tn
authored andcommitted
feat(isIdentityCard): add 'LK' (Sri Lanka) locale (#1786)
* Implement isIdentityCard LK(Sri Lanka) locale * Add tests for isIdentityCard LK locale * Update README.md for the isIdentityCard LK locale * Change let to const Co-authored-by: Sarhan Aissi <[email protected]> Co-authored-by: Sarhan Aissi <[email protected]>
1 parent 15afc77 commit dac5814

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Validator | Description
115115
**isHexColor(str)** | check if the string is a hexadecimal color.
116116
**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)`).
117117
**isIBAN(str)** | check if a string is a IBAN (International Bank Account Number).
118-
**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.<br/><br/>`locale` is one of `['PL', '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.<br/><br/>Defaults to 'any'.
118+
**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.<br/><br/>`locale` is one of `['LK', 'PL', '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.<br/><br/>Defaults to 'any'.
119119
**isIMEI(str [, options]))** | check if the string is a valid IMEI number. Imei should be of format `###############` or `##-######-######-#`.<br/><br/>`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.
120120
**isIn(str, values)** | check if the string is in a array of allowed values.
121121
**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).

src/lib/isIdentityCard.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ const validators = {
160160
}
161161
return str[12] === ((11 - (sum % 11)) % 10).toString();
162162
},
163+
LK: (str) => {
164+
const old_nic = /^[1-9]\d{8}[vx]$/i;
165+
const new_nic = /^[1-9]\d{11}$/i;
166+
167+
if (str.length === 10 && old_nic.test(str)) return true;
168+
else if (str.length === 12 && new_nic.test(str)) return true;
169+
return false;
170+
},
163171
'he-IL': (str) => {
164172
const DNI = /^\d{9}$/;
165173

test/validators.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4751,6 +4751,27 @@ describe('Validators', () => {
47514751

47524752
it('should validate identity cards', () => {
47534753
const fixtures = [
4754+
{
4755+
locale: 'LK',
4756+
valid: [
4757+
'722222222v',
4758+
'722222222V',
4759+
'993151225x',
4760+
'993151225X',
4761+
'188888388x',
4762+
'935632124V',
4763+
'199931512253',
4764+
'200023125632',
4765+
],
4766+
invalid: [
4767+
'023125648V',
4768+
'023345621v',
4769+
'021354211X',
4770+
'055321231x',
4771+
'02135465462',
4772+
'199931512253X',
4773+
],
4774+
},
47544775
{
47554776
locale: 'PL',
47564777
valid: [

0 commit comments

Comments
 (0)