Skip to content

Commit

Permalink
Merge branch 'master' into types
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin authored Jun 8, 2024
2 parents 1552e36 + d3db30d commit f4b5109
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ A clear and concise description of what the bug is.
**Examples**
If applicable, add screenshots to help explain your problem.

**Reproductions**
If applicable, provide a reproduction on platforms like [runkit](npm.runkit.com/validator)

**Additional context**
Validator.js version:
Node.js version:
Expand Down
58 changes: 26 additions & 32 deletions README.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import isISO8601 from './lib/isISO8601';
import isRFC3339 from './lib/isRFC3339';
import isISO31661Alpha2 from './lib/isISO31661Alpha2';
import isISO31661Alpha3 from './lib/isISO31661Alpha3';
import isISO31661Numeric from './lib/isISO31661Numeric';
import isISO4217 from './lib/isISO4217';

import isBase32 from './lib/isBase32';
Expand Down Expand Up @@ -210,6 +211,7 @@ const validator = {
isRFC3339,
isISO31661Alpha2,
isISO31661Alpha3,
isISO31661Numeric,
isISO4217,
isBase32,
isBase58,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/isBtcAddress.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assertString from './util/assertString';

const bech32 = /^(bc1)[a-z0-9]{25,39}$/;
const base58 = /^(1|3)[A-HJ-NP-Za-km-z1-9]{25,39}$/;
const bech32 = /^(bc1|tb1|bc1p|tb1p)[ac-hj-np-z02-9]{39,58}$/;
const base58 = /^(1|2|3|m)[A-HJ-NP-Za-km-z1-9]{25,39}$/;

export default function isBtcAddress(str) {
assertString(str);
Expand Down
7 changes: 4 additions & 3 deletions src/lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ export default function isEmail(str, options) {
}
}

if (options.blacklisted_chars) {
if (user.search(new RegExp(`[${options.blacklisted_chars}]+`, 'g')) !== -1) return false;
}

if (user[0] === '"') {
user = user.slice(1, user.length - 1);
return options.allow_utf8_local_part ?
Expand All @@ -178,9 +182,6 @@ export default function isEmail(str, options) {
return false;
}
}
if (options.blacklisted_chars) {
if (user.search(new RegExp(`[${options.blacklisted_chars}]+`, 'g')) !== -1) return false;
}

return true;
}
2 changes: 1 addition & 1 deletion src/lib/isIBAN.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const ibanRegexThroughCountryCode = {
TR: /^(TR[0-9]{2})\d{5}[A-Z0-9]{17}$/,
UA: /^(UA[0-9]{2})\d{6}[A-Z0-9]{19}$/,
VA: /^(VA[0-9]{2})\d{18}$/,
VG: /^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,
VG: /^(VG[0-9]{2})[A-Z]{4}\d{16}$/,
XK: /^(XK[0-9]{2})\d{16}$/,
};

Expand Down
26 changes: 26 additions & 0 deletions src/lib/isISO31661Numeric.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import assertString from './util/assertString';

// from https://en.wikipedia.org/wiki/ISO_3166-1_numeric
const validISO31661NumericCountriesCodes = new Set([
'004', '008', '010', '012', '016', '020', '024', '028', '031', '032', '036', '040', '044', '048', '050', '051',
'052', '056', '060', '064', '068', '070', '072', '074', '076', '084', '086', '090', '092', '096', '100', '104',
'108', '112', '116', '120', '124', '132', '136', '140', '144', '148', '152', '156', '158', '162', '166', '170',
'174', '175', '178', '180', '184', '188', '191', '192', '196', '203', '204', '208', '212', '214', '218', '222',
'226', '231', '232', '233', '234', '238', '239', '242', '246', '248', '250', '254', '258', '260', '262', '266',
'268', '270', '275', '276', '288', '292', '296', '300', '304', '308', '312', '316', '320', '324', '328', '332',
'334', '336', '340', '344', '348', '352', '356', '360', '364', '368', '372', '376', '380', '384', '388', '392',
'398', '400', '404', '408', '410', '414', '417', '418', '422', '426', '428', '430', '434', '438', '440', '442',
'446', '450', '454', '458', '462', '466', '470', '474', '478', '480', '484', '492', '496', '498', '499', '500',
'504', '508', '512', '516', '520', '524', '528', '531', '533', '534', '535', '540', '548', '554', '558', '562',
'566', '570', '574', '578', '580', '581', '583', '584', '585', '586', '591', '598', '600', '604', '608', '612',
'616', '620', '624', '626', '630', '634', '638', '642', '643', '646', '652', '654', '659', '660', '662', '663',
'666', '670', '674', '678', '682', '686', '688', '690', '694', '702', '703', '704', '705', '706', '710', '716',
'724', '728', '729', '732', '740', '744', '748', '752', '756', '760', '762', '764', '768', '772', '776', '780',
'784', '788', '792', '795', '796', '798', '800', '804', '807', '818', '826', '831', '832', '833', '834', '840',
'850', '854', '858', '860', '862', '876', '882', '887', '894',
]);

export default function isISO31661Numeric(str) {
assertString(str);
return validISO31661NumericCountriesCodes.has(str);
}
6 changes: 3 additions & 3 deletions src/lib/isISO4217.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import assertString from './util/assertString';
const validISO4217CurrencyCodes = new Set([
'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN',
'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BOV', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BZD',
'CAD', 'CDF', 'CHE', 'CHF', 'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK',
'CAD', 'CDF', 'CHE', 'CHF', 'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUP', 'CVE', 'CZK',
'DJF', 'DKK', 'DOP', 'DZD',
'EGP', 'ERN', 'ETB', 'EUR',
'FJD', 'FKP',
'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD',
'HKD', 'HNL', 'HRK', 'HTG', 'HUF',
'HKD', 'HNL', 'HTG', 'HUF',
'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK',
'JMD', 'JOD', 'JPY',
'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT',
Expand All @@ -23,7 +23,7 @@ const validISO4217CurrencyCodes = new Set([
'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLE', 'SLL', 'SOS', 'SRD', 'SSP', 'STN', 'SVC', 'SYP', 'SZL',
'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS',
'UAH', 'UGX', 'USD', 'USN', 'UYI', 'UYU', 'UYW', 'UZS',
'VES', 'VND', 'VUV',
'VED', 'VES', 'VND', 'VUV',
'WST',
'XAF', 'XAG', 'XAU', 'XBA', 'XBB', 'XBC', 'XBD', 'XCD', 'XDR', 'XOF', 'XPD', 'XPF', 'XPT', 'XSU', 'XTS', 'XUA', 'XXX',
'YER',
Expand Down
10 changes: 10 additions & 0 deletions src/lib/isIdentityCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,16 @@ const validators = {
return sum + (Number(number) * (9 - index));
}, 0);
},
PK: (str) => {
// Pakistani National Identity Number CNIC is 13 digits
const CNIC = /^[1-7][0-9]{4}-[0-9]{7}-[1-9]$/;

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

// validate the data structure
return CNIC.test(sanitized);
},
};

export default function isIdentityCard(str, locale) {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const phones = {
'en-AG': /^(?:\+1|1)268(?:464|7(?:1[3-9]|[28]\d|3[0246]|64|7[0-689]))\d{4}$/,
'en-BM': /^(\+?1)?441(((3|7)\d{6}$)|(5[0-3][0-9]\d{4}$)|(59\d{5}$))/,
'en-BS': /^(\+?1[-\s]?|0)?\(?242\)?[-\s]?\d{3}[-\s]?\d{4}$/,
'en-GB': /^(\+?44|0)7\d{9}$/,
'en-GB': /^(\+?44|0)7[1-9]\d{8}$/,
'en-GG': /^(\+?44|0)1481\d{6}$/,
'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28|55|59)\d{7}$/,
'en-GY': /^(\+592|0)6\d{6}$/,
Expand Down Expand Up @@ -83,6 +83,7 @@ const phones = {
'es-HN': /^(\+?504)?[9|8|3|2]\d{7}$/,
'es-EC': /^(\+?593|0)([2-7]|9[2-9])\d{7}$/,
'es-ES': /^(\+?34)?[6|7]\d{8}$/,
'es-GT': /^(\+?502)?[2|6|7]\d{7}$/,
'es-PE': /^(\+?51)?9\d{8}$/,
'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/,
'es-NI': /^(\+?505)\d{7,8}$/,
Expand Down Expand Up @@ -150,7 +151,7 @@ const phones = {
'th-TH': /^(\+66|66|0)\d{9}$/,
'tr-TR': /^(\+?90|0)?5\d{9}$/,
'tk-TM': /^(\+993|993|8)\d{8}$/,
'uk-UA': /^(\+?38|8)?0\d{9}$/,
'uk-UA': /^(\+?38)?0(50|6[36-8]|7[357]|9[1-9])\d{7}$/,
'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/,
'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/,
'zh-CN': /^((\+|00)86)?(1[3-9]|9[28])\d{9}$/,
Expand Down
Loading

0 comments on commit f4b5109

Please sign in to comment.