Skip to content

Commit 6e3c9f3

Browse files
committed
fix(validators): fix isdate format validation
1 parent 8c4b3b3 commit 6e3c9f3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/lib/isDate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const default_date_options = {
77
};
88

99
function isValidFormat(format) {
10-
return /(^(y{4}|y{2})[\/-](m{1,2})[\/-](d{1,2})$)|(^(m{1,2})[\/-](d{1,2})[\/-]((y{4}|y{2})$))|(^(d{1,2})[\/-](m{1,2})[\/-]((y{4}|y{2})$))/gi.test(format);
10+
return /(^(y{4}|y{2})[.\/-](m{1,2})[.\/-](d{1,2})$)|(^(m{1,2})[.\/-](d{1,2})[.\/-]((y{4}|y{2})$))|(^(d{1,2})[.\/-](m{1,2})[.\/-]((y{4}|y{2})$))/gi.test(format);
1111
}
1212

1313
function zip(date, format) {

test/validators.js

+19
Original file line numberDiff line numberDiff line change
@@ -10674,6 +10674,25 @@ describe('Validators', () => {
1067410674
'2020/03-15',
1067510675
],
1067610676
});
10677+
test({
10678+
validator: 'isDate',
10679+
args: [{ format: 'MM.DD.YYYY', delimiters: ['.'], strictMode: true }],
10680+
valid: [
10681+
'01.15.2020',
10682+
'02.15.2014',
10683+
'03.15.2014',
10684+
'02.29.2020',
10685+
],
10686+
invalid: [
10687+
'2014-02-15',
10688+
'2020-02-29',
10689+
'15-07/2002',
10690+
new Date(),
10691+
new Date([2014, 2, 15]),
10692+
new Date('2014-03-15'),
10693+
'29.02.2020',
10694+
],
10695+
});
1067710696
});
1067810697
it('should be valid license plate', () => {
1067910698
test({

0 commit comments

Comments
 (0)