0

I need to parse data from the server, some of which are supposed to be date-time values. The expected format is in the form '2017-06-16T09:00:00Z'. How can I validate that an input is in this format before I convert it into a Date object? Only this specific date-time format can be accepted as correct input for my functionality.

Apparently this format is some kind of standard convention. I would prefer not to add new libraries into my system if possible, so that means answers using AngularJS (my system is already using that) or pure JavaScript is preferred.

thegreatjedi
  • 2,788
  • 4
  • 28
  • 49
  • There're some libs can do this job for you, https://momentjs.com/ for example – dloeda Jun 16 '17 at 10:03
  • *Apparently this format is some kind of standard convention* - Yes ISO8601 so for example [Regex validate correct ISO8601 date string with time](https://stackoverflow.com/questions/28020805/regex-validate-correct-iso8601-date-string-with-time) – Alex K. Jun 16 '17 at 10:04
  • Possible duplicate of [Regex validate correct ISO8601 date string with time](https://stackoverflow.com/questions/28020805/regex-validate-correct-iso8601-date-string-with-time) – phuzi Jun 16 '17 at 11:18

0 Answers0