| re: Date format dd/mm
JRS: In article <opsfjt2xg4x13kvk@atlantis>, dated Fri, 8 Oct 2004
11:25:43, seen in news:comp.lang.javascript, Michael Winter <M.Winter@bl
ueyonder.co.invalid> posted :[color=blue]
>On 8 Oct 2004 01:32:28 -0700, Ian <ismith@cafonline.org> wrote:
>[color=green]
>> I would like to have some validation on a date field. The date format is
>> dd/mm which is used for our financial year end. I suppose I need also
>> consider leap years. Please can you shed some light on how I will be
>> able to achieve this?[/color][/color]
Best by reading the newsgroup FAQ and seeing what it says adjacent to
the words "date" / "dates". Or by following sig line 3 below.
As you give no location, one cannot guess when your FY ends; it will be,
I suppose, either this year or next year - or you may already know the
end year. If you are US, test state & month for year end; if you are
UK, test Month*100 + Date against 405 or 406; otherwise ... (actually,
the FYs of organisations do not always match those of their
surroundings; for example, IIRC, most US states do not match the Feds).
[color=blue]
>The easiest way is to validate the format of the date, then use the
>built-in Date object to verify the actual numbers are valid.[/color]
Agreed.
[color=blue]
> ...[/color]
[color=blue]
> var valid = /^([0123]\d)\/([01]\d)$/.exec(obj.value);[/color]
No need to check digit values here, though.
/^(\d\d)\D+(\d\d)$/ or /^(\d+)\D+(\d+)$/ should do, if
liberal data entry is wanted.
[color=blue]
> date.setMonth(month, day);[/color]
Possibly worth noting the importance of doing that in a single step,
since doing it in two steps will often, but not always, work, depending
on the current date & the date given.
[color=blue]
>Partially tested.[/color]
The fundamentally similar code cited can probably be considered well
tested, so yours should work!
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links. |