Skip to content

Commit b0d49bd

Browse files
authored
fix(isDate): fix isdate format validation (#1711)
1 parent 5b649c6 commit b0d49bd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/lib/isDate.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10702,6 +10702,25 @@ describe('Validators', () => {
1070210702
'2020/03-15',
1070310703
],
1070410704
});
10705+
test({
10706+
validator: 'isDate',
10707+
args: [{ format: 'MM.DD.YYYY', delimiters: ['.'], strictMode: true }],
10708+
valid: [
10709+
'01.15.2020',
10710+
'02.15.2014',
10711+
'03.15.2014',
10712+
'02.29.2020',
10713+
],
10714+
invalid: [
10715+
'2014-02-15',
10716+
'2020-02-29',
10717+
'15-07/2002',
10718+
new Date(),
10719+
new Date([2014, 2, 15]),
10720+
new Date('2014-03-15'),
10721+
'29.02.2020',
10722+
],
10723+
});
1070510724
});
1070610725
it('should be valid license plate', () => {
1070710726
test({

0 commit comments

Comments
 (0)