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

isDate returns false for all strings #2389

Open
ElimuTek opened this issue Apr 15, 2024 · 4 comments
Open

isDate returns false for all strings #2389

ElimuTek opened this issue Apr 15, 2024 · 4 comments
Labels

Comments

@ElimuTek
Copy link

isDate returns false for all strings

isDate is always returning false, even for correctly formatted strings.

Examples
validator.isDate('2024-01-01', { format: 'YYYY-MM-DD', delimiters: ['-'] }); // false
validator.isDate("2024/01/01"); // false
validator.isDate(new Date('2024-01-01')); // true
validator.isDate(validator.toDate("1")); // true

The only way I was able to make the result come back true was to coerce the date into native date format with validator.isDate(new Date(${inputValue})) or validator.isDate(validator.toDate(inputValue)). This is not a viable workaround as the last example shows (returns valid for "1").
It seems like isDate is expecting an object, but the tool is intended for string validation.
Notably other validators like isBefore and isAfter are working correctly with the same date format YYYY/MM/DD, as a string.

Additional context
Validator.js version: 13.11.0
included via cdn: <script src="https://unpkg.com/validator@latest/validator.min.js"></script>
Node.js version: 18.16.0
OS platform: windows
isDate_example_screenshot

@land-bit
Copy link

land-bit commented Apr 16, 2024

This issue is interesting. I want to work on it.

@ElimuTek
Copy link
Author

ElimuTek commented Apr 16, 2024 via email

@land-bit
Copy link

land-bit commented Apr 18, 2024 via email

@PAllisonVSO
Copy link

PAllisonVSO commented May 2, 2024

I am also seeing this issue, using the latest version 13.11.0. It's a brand new install; just started using the package today. I do love how simple it is to implement.

If it helps; I pulled the code directly in to my system and it ran fine, but my original code is in typescript. I am wondering if there is a transpile issue somewhere along the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants