Skip to content

Commit 35fc280

Browse files
authored
Merge branch 'master' into feat/Jamaica-addition
2 parents 7786bb3 + 7832d4a commit 35fc280

22 files changed

+1600
-101
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ yarn.lock
1010
/index.js
1111
validator.js
1212
validator.min.js
13+

README.md

Lines changed: 12 additions & 9 deletions
Large diffs are not rendered by default.

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import isBefore from './lib/isBefore';
6969

7070
import isIn from './lib/isIn';
7171

72+
import isLuhnValid from './lib/isLuhnValid';
7273
import isCreditCard from './lib/isCreditCard';
7374
import isIdentityCard from './lib/isIdentityCard';
7475

@@ -183,6 +184,7 @@ const validator = {
183184
isAfter,
184185
isBefore,
185186
isIn,
187+
isLuhnValid,
186188
isCreditCard,
187189
isIdentityCard,
188190
isEAN,

src/lib/alpha.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export const alpha = {
3131
ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
3232
he: /^[א-ת]+$/,
3333
fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i,
34+
bn: /^['ি']+$/,
3435
'hi-IN': /^[\u0900-\u0961]+[\u0972-\u097F]*$/i,
36+
'si-LK': /^[\u0D80-\u0DFF]+$/,
3537
};
3638

3739
export const alphanumeric = {
@@ -66,7 +68,9 @@ export const alphanumeric = {
6668
ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
6769
he: /^[0-9א-ת]+$/,
6870
fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i,
71+
bn: /^['ি']+$/,
6972
'hi-IN': /^[\u0900-\u0963]+[\u0966-\u097F]*$/i,
73+
'si-LK': /^[0-9\u0D80-\u0DFF]+$/,
7074
};
7175

7276
export const decimal = {
@@ -85,10 +89,8 @@ for (let locale, i = 0; i < englishLocales.length; i++) {
8589
}
8690

8791
// Source: http://www.localeplanet.com/java/
88-
export const arabicLocales = [
89-
'AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY',
90-
'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE',
91-
];
92+
export const arabicLocales = ['AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY',
93+
'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE'];
9294

9395
for (let locale, i = 0; i < arabicLocales.length; i++) {
9496
locale = `ar-${arabicLocales[i]}`;
@@ -97,22 +99,29 @@ for (let locale, i = 0; i < arabicLocales.length; i++) {
9799
decimal[locale] = decimal.ar;
98100
}
99101

100-
export const farsiLocales = [
101-
'IR', 'AF',
102-
];
102+
export const farsiLocales = ['IR', 'AF'];
103103

104104
for (let locale, i = 0; i < farsiLocales.length; i++) {
105105
locale = `fa-${farsiLocales[i]}`;
106106
alphanumeric[locale] = alphanumeric.fa;
107107
decimal[locale] = decimal.ar;
108108
}
109109

110+
export const bengaliLocales = ['BD', 'IN'];
111+
112+
for (let locale, i = 0; i < bengaliLocales.length; i++) {
113+
locale = `bn-${bengaliLocales[i]}`;
114+
alpha[locale] = alpha.bn;
115+
alphanumeric[locale] = alphanumeric.bn;
116+
decimal[locale] = decimal['en-US'];
117+
}
118+
110119
// Source: https://en.wikipedia.org/wiki/Decimal_mark
111120
export const dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY'];
112121
export const commaDecimal = [
113122
'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'es-ES', 'fr-CA', 'fr-FR',
114123
'id-ID', 'it-IT', 'ku-IQ', 'hi-IN', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT',
115-
'ru-RU', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN',
124+
'ru-RU', 'si-LK', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN',
116125
];
117126

118127
for (let i = 0; i < dotDecimal.length; i++) {

src/lib/isCreditCard.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import assertString from './util/assertString';
2+
import isLuhnValid from './isLuhnValid';
23

34
/* eslint-disable max-len */
45
const creditCard = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$/;
@@ -10,24 +11,5 @@ export default function isCreditCard(str) {
1011
if (!creditCard.test(sanitized)) {
1112
return false;
1213
}
13-
let sum = 0;
14-
let digit;
15-
let tmpNum;
16-
let shouldDouble;
17-
for (let i = sanitized.length - 1; i >= 0; i--) {
18-
digit = sanitized.substring(i, (i + 1));
19-
tmpNum = parseInt(digit, 10);
20-
if (shouldDouble) {
21-
tmpNum *= 2;
22-
if (tmpNum >= 10) {
23-
sum += ((tmpNum % 10) + 1);
24-
} else {
25-
sum += tmpNum;
26-
}
27-
} else {
28-
sum += tmpNum;
29-
}
30-
shouldDouble = !shouldDouble;
31-
}
32-
return !!((sum % 10) === 0 ? sanitized : false);
14+
return isLuhnValid(str);
3315
}

src/lib/isDataURI.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export default function isDataURI(str) {
1414
}
1515
const attributes = data.shift().trim().split(';');
1616
const schemeAndMediaType = attributes.shift();
17-
if (schemeAndMediaType.substr(0, 5) !== 'data:') {
17+
if (schemeAndMediaType.slice(0, 5) !== 'data:') {
1818
return false;
1919
}
20-
const mediaType = schemeAndMediaType.substr(5);
20+
const mediaType = schemeAndMediaType.slice(5);
2121
if (mediaType !== '' && !validMediaType.test(mediaType)) {
2222
return false;
2323
}

src/lib/isEmail.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default function isEmail(str, options) {
7777
// eg. myname <[email protected]>
7878
// the display name is `myname` instead of `myname `, so need to trim the last space
7979
if (display_name.endsWith(' ')) {
80-
display_name = display_name.substr(0, display_name.length - 1);
80+
display_name = display_name.slice(0, -1);
8181
}
8282

8383
if (!validateDisplayName(display_name)) {
@@ -144,7 +144,7 @@ export default function isEmail(str, options) {
144144
return false;
145145
}
146146

147-
let noBracketdomain = domain.substr(1, domain.length - 2);
147+
let noBracketdomain = domain.slice(1, -1);
148148

149149
if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) {
150150
return false;

src/lib/isFQDN.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default function isFQDN(str, options) {
3232
return false;
3333
}
3434

35-
if (!/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
35+
if (!options.allow_numeric_tld && !/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
3636
return false;
3737
}
3838

src/lib/isIP.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,10 @@ export default function isIP(str, version = '') {
5151
return isIP(str, 4) || isIP(str, 6);
5252
}
5353
if (version === '4') {
54-
if (!IPv4AddressRegExp.test(str)) {
55-
return false;
56-
}
57-
const parts = str.split('.').sort((a, b) => a - b);
58-
return parts[3] <= 255;
54+
return IPv4AddressRegExp.test(str);
5955
}
6056
if (version === '6') {
61-
return !!IPv6AddressRegExp.test(str);
57+
return IPv6AddressRegExp.test(str);
6258
}
6359
return false;
6460
}

src/lib/isIdentityCard.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ const validators = {
130130
},
131131
IR: (str) => {
132132
if (!str.match(/^\d{10}$/)) return false;
133-
str = (`0000${str}`).substr(str.length - 6);
133+
str = (`0000${str}`).slice(str.length - 6);
134134

135-
if (parseInt(str.substr(3, 6), 10) === 0) return false;
135+
if (parseInt(str.slice(3, 9), 10) === 0) return false;
136136

137-
const lastNumber = parseInt(str.substr(9, 1), 10);
137+
const lastNumber = parseInt(str.slice(9, 10), 10);
138138
let sum = 0;
139139

140140
for (let i = 0; i < 9; i++) {
141-
sum += parseInt(str.substr(i, 1), 10) * (10 - i);
141+
sum += parseInt(str.slice(i, i + 1), 10) * (10 - i);
142142
}
143143

144144
sum %= 11;

0 commit comments

Comments
 (0)