Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date Validation in Nodejs

I want the user to input his date of birth. And I would want it be in format YYYY-MM-DD. Node-Validator right now validates all date format, not a particular format. So If I input 12324433 , it is also validated as it thinks its epoch time.

Please help me out as to what should I do? This question is specific to validation in Mongoose

like image 975
Saransh Mohapatra Avatar asked Jul 02 '13 18:07

Saransh Mohapatra


1 Answers

I'm a big fan of express-form, def worth a look -- you can also use moment.js. I've used it myself a for this very reason

from moment.js docs:

moment("2011-10-10", "YYYY-MM-DD").isValid(); // true
moment("2011-10-50", "YYYY-MM-DD").isValid(); // false (bad day of month)

Cheers, I hope this helps :)

ps - moment.js github url just in case.

like image 120
David Avatar answered Sep 17 '22 17:09

David