Again thanks very much. This is for an internal database capture page only
used by one person so this format will be perfect.
Pete
"Lasse Reichstein Nielsen" <lrn@hotpop.com> wrote in message
news:d6a4984f.fsf@hotpop.com...[color=blue]
> "Pete" <pete@pete.com> writes:
>[color=green]
> > I don't want to be a pain or to hassle you but do you know how I can get[/color][/color]
it[color=blue][color=green]
> > to accept dates in the dd/mm/yy format.[/color]
>
> Don't. That notation is so ambiguous, especially in an international
> forum, that 03/04/05 can reasonably be expected to be read as any of
> 3rd of April 2005, 4th of March 2005 or 5th of April 2003. It is
> better to train your users to write unambiguous formats like
> 2003-12-31. :)
>
> Now, if you (or someone you work for :) insist on using dd/mm/yy, then
> I suggest parsing it yourself instead of using the Date constructor.
>
> Try:
>
> ---
> function parseDate(string) {
> // test that format is two digits - slash - two digits - slash - two[/color]
digits[color=blue]
> var match = string.match(/^(\d{2})\/(\d{2})\/(\d{2})$/);
> if (!match) {return null;} // incorrect format.
>
> var year = Number(match[3]);
> if (year<70) { // 72 -> 1972, but 05 -> 2005
> year += 2000;
> } else {
> year += 1900;
> }
> var month = Number(match[2])-1; // Date uses 0=January.
> var date = Number(match[1]);
>
> var theDate = new Date(year,month,date);
> if (theDate.getDate()!=date || theDate.getMonth()!=month) {
> return null; // illegal date, e.g., date=32 or month=13
> }
>
> return theDate;
> }
> ---
>
> Good luck.
>
> (please don't top post/remember to trim the quotes)
> /L
> --
> Lasse Reichstein Nielsen -
lrn@hotpop.com
> DHTML Death Colors:[/color]
<URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>[color=blue]
> 'Faith without judgement merely degrades the spirit divine.'[/color]