Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fix-lat-long-vali…
Browse files Browse the repository at this point in the history
…dation
  • Loading branch information
ezkemboi committed Aug 2, 2019
2 parents 6a1d78d + 1ce76a1 commit 1a5fe9a
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/isLatLong.js
Expand Up @@ -16,7 +16,7 @@ function _default(str) {
(0, _assertString.default)(str);
if (!str.includes(',')) return false;
var pair = str.split(',');
if (pair[0].charAt(0) === '(' && pair[1].charAt(pair[1].length - 1) !== ')' || pair[1].charAt(pair[1].length - 1) === ')' && pair[0].charAt(0) !== '(') return false;
if (pair[0].startsWith('(') && !pair[1].endsWith(')') || pair[1].endsWith(')') && !pair[0].startsWith('(')) return false;
return lat.test(pair[0]) && long.test(pair[1]);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/isLength.js
Expand Up @@ -22,7 +22,7 @@ function isLength(str, options) {
max = options.max;
} else {
// backwards compatibility: isLength(str, min [, max])
min = arguments[1];
min = arguments[1] || 0;
max = arguments[2];
}

Expand Down
2 changes: 1 addition & 1 deletion lib/isMobilePhone.js
Expand Up @@ -68,7 +68,7 @@ var phones = {
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
'ja-JP': /^(\+?81|0)[789]0[ \-]?[1-9]\d{2}[ \-]?\d{5}$/,
'ja-JP': /^(\+?81|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
'kk-KZ': /^(\+?7|8)?7\d{9}$/,
'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
Expand Down
6 changes: 2 additions & 4 deletions src/lib/isLatLong.js
Expand Up @@ -7,9 +7,7 @@ export default function (str) {
assertString(str);
if (!str.includes(',')) return false;
const pair = str.split(',');
if (
(pair[0].charAt(0) === '(' && pair[1].charAt(pair[1].length - 1) !== ')') ||
(pair[1].charAt(pair[1].length - 1) === ')' && pair[0].charAt(0) !== '(')
) return false;
if ((pair[0].startsWith('(') && !pair[1].endsWith(')'))
|| (pair[1].endsWith(')') && !pair[0].startsWith('('))) return false;
return lat.test(pair[0]) && long.test(pair[1]);
}
2 changes: 1 addition & 1 deletion src/lib/isLength.js
Expand Up @@ -9,7 +9,7 @@ export default function isLength(str, options) {
min = options.min || 0;
max = options.max;
} else { // backwards compatibility: isLength(str, min [, max])
min = arguments[1];
min = arguments[1] || 0;
max = arguments[2];
}
const surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isMobilePhone.js
Expand Up @@ -58,7 +58,7 @@ const phones = {
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
'ja-JP': /^(\+?81|0)[789]0[ \-]?[1-9]\d{2}[ \-]?\d{5}$/,
'ja-JP': /^(\+?81|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
'kk-KZ': /^(\+?7|8)?7\d{9}$/,
'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
Expand Down
14 changes: 10 additions & 4 deletions test/validators.js
Expand Up @@ -2795,6 +2795,10 @@ describe('Validators', () => {
valid: [''],
invalid: ['a', 'ab'],
});
test({
validator: 'isLength',
valid: ['a', '', 'asds'],
});
});

it('should validate strings by byte length', () => {
Expand Down Expand Up @@ -4779,9 +4783,12 @@ describe('Validators', () => {
{
locale: 'ja-JP',
valid: [
'09012345688',
'090 123 45678',
'+8190-123-45678',
'09012345678',
'08012345678',
'07012345678',
'06012345678',
'090 1234 5678',
'+8190-1234-5678',
],
invalid: [
'12345',
Expand All @@ -4794,7 +4801,6 @@ describe('Validators', () => {
'03_1234_5689',
'0312345678',
'0721234567',
'08002345678',
'06 1234 5678',
'072 123 4567',
'0729 12 3456',
Expand Down
6 changes: 3 additions & 3 deletions validator.js
Expand Up @@ -1007,7 +1007,7 @@ function isLength(str, options) {
max = options.max;
} else {
// backwards compatibility: isLength(str, min [, max])
min = arguments[1];
min = arguments[1] || 0;
max = arguments[2];
}

Expand Down Expand Up @@ -1399,7 +1399,7 @@ var phones = {
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
'ja-JP': /^(\+?81|0)[789]0[ \-]?[1-9]\d{2}[ \-]?\d{5}$/,
'ja-JP': /^(\+?81|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
'kk-KZ': /^(\+?7|8)?7\d{9}$/,
'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
Expand Down Expand Up @@ -1739,7 +1739,7 @@ var isLatLong = function (str) {
assertString(str);
if (!str.includes(',')) return false;
var pair = str.split(',');
if (pair[0].charAt(0) === '(' && pair[1].charAt(pair[1].length - 1) !== ')' || pair[1].charAt(pair[1].length - 1) === ')' && pair[0].charAt(0) !== '(') return false;
if (pair[0].startsWith('(') && !pair[1].endsWith(')') || pair[1].endsWith(')') && !pair[0].startsWith('(')) return false;
return lat.test(pair[0]) && _long.test(pair[1]);
};

Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit 1a5fe9a

Please sign in to comment.