Ilya
Ilya

Reputation: 29693

Date.parse() doesn't work in IE 8

Simple function Date.parse() not working well in Internet Explorer 8.
I am using Date.parse() to validate date in format "MM/DD/YYYY".

But now I tried my JavaScript in IE 8 and I'm confused.

jsFiddle Demo

Any ideas?

Upvotes: 3

Views: 6569

Answers (3)

Ilya
Ilya

Reputation: 29693

I used my method for date validation

   var isValidDate = function(dateAsString)
   {
      var parsedDate = Date.parse(dateAsString);
      if (_.isNaN(parsedDate) || !_.isEqual(new Date(parsedDate).format("mm/dd/yyyy"), dateAsString))
      {
         return false
      }

      return true
   }

Upvotes: 0

Ilia Frenkel
Ilia Frenkel

Reputation: 1977

Look here, here and here. In general Date.parse() is not a cross browser solution. There are a lot of plugins and libraries available, just google it.

Upvotes: 1

Pointy
Pointy

Reputation: 413737

Standard JavaScript only accepts RFC 2822 dates, which don't look like that. You'll have to write your own code to separate out the date parts, convert them to numbers, and make Date instances that way.

Internet Explorer also supports ISO dates (2012-09-20 08:22), and it will in fact parse "MM/DD/YYYY" dates. It's doing that for your "13/35/2012" date, which as far as JavaScript is concerned is a perfectly valid date: it's 04 February 2013. JavaScript "fixes" bogus dates; the 13th month of the year is the first month of the following year, and the 35th day of the month (if it's January, with 31 days) is the fourth day of the next month.

Basically you're expecting the Date parser to behave differently than it actually does.

Upvotes: 3

Related Questions