I'm trying to test to make sure a date is valid in the sense that if someone enters 2/30/2011
then it should be wrong.
How can I do this with any date?
I'm trying to test to make sure a date is valid in the sense that if someone enters 2/30/2011
then it should be wrong.
How can I do this with any date?
Hi Please find the answer below.this is done by validating the date newly created
My function returns true if is a valid date otherwise returns false :D
This is JS6 (with let declaration).
In this case I've intended months from 1 to 12. If you prefer or use the 0-11 based model, you can just change the arrays with:
If your date is in form dd/mm/yyyy than you can take off day, month and year function parameters, and do this to retrieve them:
Though this was raised long ago, still a most wanted validation. I found an interesting blog with few function.
copy the whole code into a file and include.
hope this helps.
Does first function isValidDate(s) proposed by RobG will work for input string '1/2/'? I think NOT, because the YEAR is not validated ;(
My proposition is to use improved version of this function:
I recommend to use moment.js. Only providing date to moment will validate it, no need to pass the dateFormat.
And then
date.isValid()
gives desired result.Se post HERE