Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/isDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export default function isDate(input, options) {
if (options.strictMode && input.length !== options.format.length) return false;
const formatDelimiter = options.delimiters
.find(delimiter => options.format.indexOf(delimiter) !== -1);

// The format's delimiter is not one of the allowed delimiters, so no input can match it.
if (formatDelimiter === undefined) return false;

const dateDelimiter = options.strictMode
? formatDelimiter
: options.delimiters.find(delimiter => input.indexOf(delimiter) !== -1);
Expand Down
25 changes: 25 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14671,6 +14671,31 @@ describe('Validators', () => {
'abc.04.05.2024',
],
});
test({
validator: 'isDate',
args: [{ format: 'DD.MM.YYYY' }], // '.' is not in the default delimiters
invalid: [
'29.02.2020',
'29/02/2020',
'29-02-2020',
],
});
test({
validator: 'isDate',
args: ['YYYY.MM.DD'], // old format for backward compatibility
invalid: [
'2020.02.29',
'2020/02/29',
],
});
test({
validator: 'isDate',
args: [{ format: 'YYYY-MM-DD', delimiters: ['/'] }],
invalid: [
'2020-02-29',
'2020/02/29',
],
});
// emulating Pacific time zone offset & time
// which could potentially result in UTC conversion issues
timezone_mock.register('US/Pacific');
Expand Down
Loading