473,836 Members | 1,455 Online

# Leap Yr regular expression

can someone give the regular expr. to validate leap yr like
02/29/2000,02/29/00

Thanks

Feb 17 '06
22 4465
On Sat, 18 Feb 2006 19:09:12 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com > wrote:
Sure, this example exploits a JS implementation, but it seems to be
similar between the browsers.

No exploit, it is behaving as expected, and should work in all compliant
implementations (except for years 0-99 where the year might be normalized
to 1900-1999).

I would change "== 2) ? 0 : 1" to just "!= 2".

Sorry, you mean "!=1" ?

Feb 18 '06 #11
[...] Lasse Reichstein Nielsen [...] wrote:
I would change "== 2) ? 0 : 1" to just "!= 2".

Sorry, you mean "!=1" ?

No, that would not be equivalent.

`(x == 2) ? 0 : 1' yields 0 (false) if x equals 2, 1 (true) otherwise.
`x != 1' yields true if x equals 2, false otherwise.

He means

`x != 2' which yields false if x equals 2, true otherwise.
PointedEars
Feb 18 '06 #12
On Sat, 18 Feb 2006 19:38:02 +0200, Thomas 'PointedEars' Lahn
<Po*********@we b.de> wrote:
[...] Lasse Reichstein Nielsen [...] wrote:
I would change "== 2) ? 0 : 1" to just "!= 2".

Sorry, you mean "!=1" ?

No, that would not be equivalent.

`(x == 2) ? 0 : 1' yields 0 (false) if x equals 2, 1 (true) otherwise.
`x != 1' yields true if x equals 2, false otherwise.

He means

`x != 2' which yields false if x equals 2, true otherwise.
PointedEars

I think you all didn't understand the point:

When you create a date = YYYY.02.29 for a non-leap year, you get back a
YYYY.03.01.
And the getMonth() for the "March" is equal to 2 (for february = 1).

That's why I called it kinda an exploit (unexpected (for me) behaviour).

Feb 18 '06 #13
On Sat, 18 Feb 2006 20:08:19 +0200, Vladas Saulis <vl****@prodata .lt>
wrote:
On Sat, 18 Feb 2006 19:38:02 +0200, Thomas 'PointedEars' Lahn
<Po*********@we b.de> wrote:
[...] Lasse Reichstein Nielsen [...] wrote:
I would change "== 2) ? 0 : 1" to just "!= 2".

Sorry, you mean "!=1" ?

He he, I also missed the point... Sorry. He meant to replace *whole*
expression to "!=2"?
In this I agree.

Feb 18 '06 #14
JRS: In article <11************ **********@f14g 2000cwb.googleg roups.com>
, dated Sat, 18 Feb 2006 02:49:18 remote, seen in
news:comp.lang. javascript, VK <sc**********@y ahoo.com> posted :
It is possible to imagine (but I have no idea if it indeed exists) that
by studying "1900", "1901" etc. *string sequences* one can discover a
pattern for strings representing a number divisible by four.
That's actually trivial to express, and the expression must be rather
like

JulianLeap = /([02468][048]|[13579][26])\$/.test(Year)

// now check that year is divisible by four and return true or false
// also welcome to add any amount extra checks for the correct input:

Your presumed country, under the benevolent rule of His Majesty George
II, upgraded from that rule in 1752. Luke, ch10, v37, tail.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Feb 18 '06 #15
JRS: In article <op.s458uhm28lq gld@eightpee>, dated Sat, 18 Feb 2006
15:52:55 remote, seen in news:comp.lang. javascript, Vladas Saulis
<vl****@prodata .lt> posted :
It's curious, but I found this working with ALL known (for me) browsers:

function isLeapYear(year ) {

return ((new Date(year, 1, 29, 0, 0).getMonth() == 2) ? 0 : 1);
}

A function of that nature should return a Boolean :

return new Date(year, 1, 29, 0, 0).getMonth() != 2

The following is preferable, though the programmer can do the addition :

return !new Date(year, 0, 366+31).getMont h()

--
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Feb 18 '06 #16
On 18/02/2006 18:08, Vladas Saulis wrote:

[snip]
When you create a date = YYYY.02.29 for a non-leap year, you get back
a YYYY.03.01. And the getMonth() for the "March" is equal to 2 (for
february = 1).

That's why I called it kinda an exploit (unexpected (for me)
behaviour).

However, it /is/ expected behaviour. The Date object is well-known for
by design.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Feb 19 '06 #17
JRS: In article <ko************ ******@text.new s.blueyonder.co .uk>,
dated Sun, 19 Feb 2006 00:57:52 remote, seen in
news:comp.lang. javascript, Michael Winter <m.******@bluey onder.co.uk>
posted :
On 18/02/2006 18:08, Vladas Saulis wrote:

[snip]
When you create a date = YYYY.02.29 for a non-leap year, you get back
a YYYY.03.01. And the getMonth() for the "March" is equal to 2 (for
february = 1).

That's why I called it kinda an exploit (unexpected (for me)
behaviour).

However, it /is/ expected behaviour. The Date object is well-known for
by design.

For those who injudiciously put VBscript on Web pages, or who more
sagaciously use VBscript in WSH :

Functions DateSerial and TimeSerial have corresponding behaviour.

--
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Feb 19 '06 #18
Dr John Stockton said the following on 2/19/2006 3:04 PM:
JRS: In article <ko************ ******@text.new s.blueyonder.co .uk>,
dated Sun, 19 Feb 2006 00:57:52 remote, seen in
news:comp.lang. javascript, Michael Winter <m.******@bluey onder.co.uk>
posted :
On 18/02/2006 18:08, Vladas Saulis wrote:

[snip]
When you create a date = YYYY.02.29 for a non-leap year, you get back
a YYYY.03.01. And the getMonth() for the "March" is equal to 2 (for
february = 1).

That's why I called it kinda an exploit (unexpected (for me)
behaviour). However, it /is/ expected behaviour. The Date object is well-known for
by design.

For those who injudiciously put VBscript on Web pages,

There is nothing "injudiciou s" about putting VBScript on Web pages.

It's wise if you know when, its ignorant if you don't.
or who more sagaciously use VBscript in WSH :

Sesquipedalian behavior is a sign of ignorance, not intelligence.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 20 '06 #19
On Sun, 19 Feb 2006 02:57:52 +0200, Michael Winter
<m.******@bluey onder.co.uk> wrote:
On 18/02/2006 18:08, Vladas Saulis wrote:

[snip]
When you create a date = YYYY.02.29 for a non-leap year, you get back
a YYYY.03.01. And the getMonth() for the "March" is equal to 2 (for
february = 1).
That's why I called it kinda an exploit (unexpected (for me)
behaviour).

However, it /is/ expected behaviour. The Date object is well-known for
by design.

Following this logic, then the date = YYYY.MM.00 should return the last
day of the previous month.
Am I right? (I have no time to test :).