question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hi,

I hope somebody can help me figure out what I’m doing wrong:

req.checkBody('profile.dateOfBirth', 'Date of birth needs to be a valid date').isDate({format: 'DD-MM-YYYY'});

Yields the following validation error:

{
    "param": "profile.dateOfBirth",
    "msg": "Date of birth needs to be a valid date",
    "value": "22-06-1977"
}

I tried with different format strings, no format string, etc but the result is always the same. All other validations (notEmpty, isAlpha, len, etc) on other params work as expected only isDate consistently fails.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
gustavohenkecommented, Jan 14, 2018

Hi @afrikhero @Pedro-Sousa-da-Rocha, isISO8601 is probably the best method from validator to validate dates.

3reactions
rustybaileycommented, Jun 25, 2015

express-validator is simply a middleware wrapper of validator.js, so all available validators are listed on their README. Just looking at their docs/code, the isDate method does not accept an object for specifying a format. Behind the scenes, this is how it is validated:

    validator.isDate = function (str) {
        return !isNaN(Date.parse(str));
    };

So in order for isDate to work, you will either need to:

  1. Remove the object when calling it.
  2. Create a PR to validator.js to add the format functionality.
  3. Create a custom validator that checks for that format using regex or moment.js’s isValid().

Let me know if this works. If so, please close the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL Server ISDATE() Function - W3Schools
The ISDATE() function checks an expression and returns 1 if it is a valid date, otherwise 0. Syntax. ISDATE(expression). Parameter Values ...
Read more >
ISDATE (Transact-SQL) - SQL Server - Microsoft Learn
In this article ... Returns 1 if the expression is a valid datetime value; otherwise, 0. ISDATE returns 0 if the expression is...
Read more >
SQL Server ISDATE() Function By Practical Examples
The ISDATE() function accepts an argument and returns 1 if that argument is a valid DATE , TIME , or DATETIME value; otherwise,...
Read more >
SQL ISDATE Function Use and Examples
The ISDATE function returns 1 if the parameter value is a valid date and 0 if it is not a valid date. Syntax....
Read more >
ISDATE() Function in SQL Server - GeeksforGeeks
ISDATE() Function in SQL Server · This function is used to find if the stated date is valid or not. · This function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found