Skip to content
Merged
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
7 changes: 6 additions & 1 deletion src/lib/isDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12957,6 +12957,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({
Expand Down