1

I want to validate following date format in javascript.

01/26/2016 01:26:52 pm //true

01/26/2016 13:26:52 am //false

I have search on google, but not able to get regular expression which validate above date format.So please let me know how can I validate above date using regular expression.

3
  • Have a look at this regular-expressions.info/dates.html Commented Apr 29, 2016 at 9:45
  • You would not normally (should not...) use a 2 digit hour with am/pm - ie 01:26 is always 1am. 1:26 could be am or pm. Commented Apr 29, 2016 at 9:53
  • 1
    Regex is really not the best way of doing this, due to the hundreds of different formats. Commented Apr 29, 2016 at 9:55

1 Answer 1

3

Using Regex to validate the date is not a good idea in my opinion. You can instead try to use the Date object. Something like

alert(new Date("01/26/2016 01:26:52 PM"))

or

alert(new Date("01/26/2016 13:26:52 AM"))

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.