Skip to content

Commit bb00fa6

Browse files
authored
Merge 7a85ae8 into de48970
2 parents de48970 + 7a85ae8 commit bb00fa6

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Validator | Description
114114
**isHexColor(str)** | check if the string is a hexadecimal color.
115115
**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)`).
116116
**isIBAN(str)** | check if a string is a IBAN (International Bank Account Number).
117-
**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.<br/><br/>`locale` is one of `['ES', 'IN', 'IT', 'NO', 'zh-TW', 'he-IL', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.<br/><br/>Defaults to 'any'.
117+
**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.<br/><br/>`locale` is one of `['ES', 'IN', 'IT', 'NO', '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'.
118118
**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.
119119
**isIn(str, values)** | check if the string is in a array of allowed values.
120120
**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).
@@ -143,7 +143,7 @@ Validator | Description
143143
**isMultibyte(str)** | check if the string contains one or more multibyte chars.
144144
**isNumeric(str [, options])** | check if the string contains only numbers.<br/><br/>`options` is an object which defaults to `{no_symbols: false}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).<br/><br/>`locale` determine the decimal separator and is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'fr-CA', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`.
145145
**isOctal(str)** | check if the string is a valid octal number.
146-
**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.<br/><br/>(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'MT', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`.
146+
**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.<br/><br/>(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`.
147147
**isPort(str)** | check if the string is a valid port number.
148148
**isPostalCode(str, locale)** | check if the string is a postal code,<br/><br/>(locale is one of `[ 'AD', 'AT', 'AU', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'TH', 'TN', 'TW', 'UA', 'US', 'ZA', 'ZM' ]` OR 'any'. If 'any' is used, function will check if any of the locals match. Locale list is `validator.isPostalCodeLocales`.).
149149
**isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date.

src/lib/isIdentityCard.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ const validators = {
119119
}
120120
return sum % 10 === 0;
121121
},
122+
'ar-LY': (str) => {
123+
// Libya National Identity Number NIN is 12 digits, the first digit is either 1 or 2
124+
const NIN = /^(1|2)\d{11}$/;
125+
126+
// sanitize user input
127+
const sanitized = str.trim();
128+
129+
// validate the data structure
130+
if (!NIN.test(sanitized)) {
131+
return false;
132+
}
133+
return true;
134+
},
122135
'ar-TN': (str) => {
123136
const DNI = /^\d{8}$/;
124137

src/lib/isPassportNumber.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const passportRegexByCountryCode = {
3939
LT: /^[A-Z0-9]{8}$/, // LITHUANIA
4040
LU: /^[A-Z0-9]{8}$/, // LUXEMBURG
4141
LV: /^[A-Z0-9]{2}\d{7}$/, // LATVIA
42+
LY: /^[A-Z0-9]{8}$/, // LIBYA
4243
MT: /^\d{7}$/, // MALTA
4344
NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/, // NETHERLANDS
4445
PO: /^[A-Z]{2}\d{7}$/, // POLAND

test/validators.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,6 +2593,20 @@ describe('Validators', () => {
25932593
],
25942594
});
25952595

2596+
test({
2597+
validator: 'isPassportNumber',
2598+
args: ['LY'],
2599+
valid: [
2600+
'P79JF34X',
2601+
'RJ45H4V2',
2602+
],
2603+
invalid: [
2604+
'P79JF34',
2605+
'RJ45H4V2C',
2606+
'RJ4-H4V2',
2607+
],
2608+
});
2609+
25962610
test({
25972611
validator: 'isPassportNumber',
25982612
args: ['MT'],
@@ -4463,6 +4477,24 @@ describe('Validators', () => {
44634477
'336000842',
44644478
],
44654479
},
4480+
{
4481+
locale: 'ar-LY',
4482+
valid: [
4483+
'119803455876',
4484+
'120024679875',
4485+
'219624876201',
4486+
'220103480657',
4487+
],
4488+
invalid: [
4489+
'987654320123',
4490+
'123-456-7890',
4491+
'012345678912',
4492+
'1234567890',
4493+
'AFJBHUYTREWR',
4494+
'C4V6B1X0M5T6',
4495+
'9876543210123',
4496+
],
4497+
},
44664498
{
44674499
locale: 'ar-TN',
44684500
valid: [

0 commit comments

Comments
 (0)