Skip to content

Commit

Permalink
Merge 7a85ae8 into de48970
Browse files Browse the repository at this point in the history
  • Loading branch information
asghaier76 authored Feb 26, 2021
2 parents de48970 + 7a85ae8 commit bb00fa6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,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)`).
**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.<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'.
**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'.
**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.
**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).
Expand Down Expand Up @@ -143,7 +143,7 @@ Validator | Description
**isMultibyte(str)** | check if the string contains one or more multibyte chars.
**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']`.
**isOctal(str)** | check if the string is a valid octal number.
**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' ]`.
**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' ]`.
**isPort(str)** | check if the string is a valid port number.
**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`.).
**isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date.
Expand Down
13 changes: 13 additions & 0 deletions src/lib/isIdentityCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ const validators = {
}
return sum % 10 === 0;
},
'ar-LY': (str) => {
// Libya National Identity Number NIN is 12 digits, the first digit is either 1 or 2
const NIN = /^(1|2)\d{11}$/;

// sanitize user input
const sanitized = str.trim();

// validate the data structure
if (!NIN.test(sanitized)) {
return false;
}
return true;
},
'ar-TN': (str) => {
const DNI = /^\d{8}$/;

Expand Down
1 change: 1 addition & 0 deletions src/lib/isPassportNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const passportRegexByCountryCode = {
LT: /^[A-Z0-9]{8}$/, // LITHUANIA
LU: /^[A-Z0-9]{8}$/, // LUXEMBURG
LV: /^[A-Z0-9]{2}\d{7}$/, // LATVIA
LY: /^[A-Z0-9]{8}$/, // LIBYA
MT: /^\d{7}$/, // MALTA
NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/, // NETHERLANDS
PO: /^[A-Z]{2}\d{7}$/, // POLAND
Expand Down
32 changes: 32 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -2593,6 +2593,20 @@ describe('Validators', () => {
],
});

test({
validator: 'isPassportNumber',
args: ['LY'],
valid: [
'P79JF34X',
'RJ45H4V2',
],
invalid: [
'P79JF34',
'RJ45H4V2C',
'RJ4-H4V2',
],
});

test({
validator: 'isPassportNumber',
args: ['MT'],
Expand Down Expand Up @@ -4463,6 +4477,24 @@ describe('Validators', () => {
'336000842',
],
},
{
locale: 'ar-LY',
valid: [
'119803455876',
'120024679875',
'219624876201',
'220103480657',
],
invalid: [
'987654320123',
'123-456-7890',
'012345678912',
'1234567890',
'AFJBHUYTREWR',
'C4V6B1X0M5T6',
'9876543210123',
],
},
{
locale: 'ar-TN',
valid: [
Expand Down

0 comments on commit bb00fa6

Please sign in to comment.