0

Javascript:

function ValidDate(y, m, d)
{ // m = 0..11 ; y m d integers, y!=0
  with (new Date(y, m, d))
    return (getMonth()==m && getDate()==d); /* was y, m */
}
Naftali
  • 144,921
  • 39
  • 244
  • 303
Joshua Fricke
  • 381
  • 3
  • 14

2 Answers2

4

Simple:

function ValidDate(y, m, d) {
  var date = new Date(y, m, d);
  return date.getMonth() == m && date.getDate() == d;
}
Naftali
  • 144,921
  • 39
  • 244
  • 303
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
3

with makes it so that the this scope is the statement in the with so you don't have to do any .functionName(...)

What you can do:

function ValidDate(y, m, d)
{ // m = 0..11 ; y m d integers, y!=0
    var date = new Date(y, m, d);
    return (date.getMonth()==m && date.getDate()==d); /* was y, m */
}
Naftali
  • 144,921
  • 39
  • 244
  • 303