I want to validate that calendar object should be as 2014-05-05T12:12:30.How to validate a this using regular expression
Asked
Active
Viewed 7,313 times
-2
-
take a look at this thread, it is JS but very simil arhttp://stackoverflow.com/a/12756279/2362664 – Khinsu Jul 24 '14 at 15:35
-
Depending on what you really want to achieve you can use the built-in functionality of the Joda datetime library. Check out the function [ISODateTimeFormat.dateTimeParser()](http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTimeParser()). – MicSim Jul 24 '14 at 15:45
2 Answers
0
This regex will only match dates in that format with a few restrictions:
(19|20)[0-9][0-9]-(0[0-9]|1[0-2])-(0[1-9]|([12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]
This matches years 1900-2099, 12 months, up to 31 days, 24 hr clock, up to 59 minutes, up to 59 seconds
It should be noted that if you wish to validate whether or not something is a truly valid date (ie not Feb 30) you will need either a far more complex regex, or some simple code to wrap around it.
Adam Yost
- 3,534
- 21
- 36