Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation Hyphen before year is not allowed #2381

Merged
merged 3 commits into from Apr 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/lib/isDate.js
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