diff --git a/src/lib/isDate.js b/src/lib/isDate.js index f0b28917a..dc69b3bc1 100644 --- a/src/lib/isDate.js +++ b/src/lib/isDate.js @@ -22,7 +22,7 @@ function zip(date, format) { } export default function isDate(input, options) { - if (typeof options === 'string') { // Allow backward compatbility for old format isDate(input [, format]) + if (typeof options === 'string') { // Allow backward compatibility for old format isDate(input [, format]) options = merge({ format: options }, default_date_options); } else { options = merge(options, default_date_options); @@ -49,6 +49,11 @@ export default function isDate(input, options) { let fullYear = dateObj.y; + // Check if the year starts with a hyphen + if (fullYear.startsWith('-')) { + return false; // Hyphen before year is not allowed + } + if (dateObj.y.length === 2) { const parsedYear = parseInt(dateObj.y, 10); diff --git a/test/validators.test.js b/test/validators.test.js index 2ad2ce7a9..11f511aa7 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -13087,6 +13087,8 @@ describe('Validators', () => { '2019-02-29', // non-leap year '2020-04-31', // invalid date '2020/03-15', // mixed delimiter + '-2020-04-19', + '-2023/05/24', ], }); test({