[quoted text, click to view] Mark Rae wrote:
> I may be maligning you unfairly. I simply went to the site that Eliyahu
> mentioned (
http://www.mattkruse.com/javascript/date/), entered the string
> '15 Sep 2005' in the Free-Form Date Field text box, and clicked
> parseDate() - the message was "Date string does not match any recognized
> formats!"
This is true. There are two different things, here:
isDate() requires a date format to validate against. If you specify the
correct date format, isDate will correctly tell you that '15 Sep 2005'
is valid.
parseDate() tries to parse a free-form string into a date object. Since
there are obviously many different possible date formats you can enter,
it checks some common formats. It's meant as a last-resort for figuring
out a date that a user entered into a free-form field. It's always
preferred that a format is required and specified for the user, and
their value is validated against the format.
[quoted text, click to view] >From the code comments:
// ------------------------------------------------------------------
// parseDate( date_string [, prefer_euro_format] )
//
// This function takes a date string and tries to match it to a
// number of possible date formats to get the value. It will try to
// match against the following international formats, in this order:
// y-M-d MMM d, y MMM d,y y-MMM-d d-MMM-y MMM d
// M/d/y M-d-y M.d.y MMM-d M/d M-d
// d/M/y d-M-y d.M.y d-MMM d/M d-M
// A second argument may be passed to instruct the method to search
// for formats like d/M/y (european format) before M/d/y (American).
// Returns a Date object or null if no patterns match.
// ------------------------------------------------------------------
The format you're looking for, 'dd MMM yyyy' isn't one of the formats
that are automatically checked, so it will not recognize your date.
You can either use the getDateFromFormat function, which takes a string
and a format, or you can modify the parseDate code to check for more
date formats that you wish to check for. I got most of the common ones,
but perhaps 'dd MMM yyyy' should be included in there also :)
Matt Kruse
http://www.mattkruse.com