Question: Checking Date these dates fail What do I need to change?

```
20 Jan 2013
20 jan 2013
20 JAN 2013
2 Jan 2013
30 Jan 2013
20 feb 2013
20 jun 2013

```

Code:

```
function ValidateFutureDate(alertstring,pCheckDate)
{
        // Default Return Variable to return success.
        var returnSuccess = 1;

        // setup a temporary array.
        var temp = new Array();

        // split the date into the array.
        temp = pCheckDate.split(' ');

        // Setup the Test Date 
        var testDate = new Date ( temp[1]+" "+temp[0]+", "+temp[2] );
        var testMonth=testDate.getMonth()+1;
        if  (testMonth<10)
        {
            testMonth = "0"+testDate.getMonth();
        } 
        // This is the Date to test if it is a valid date.        
        var testIsDate = ( testMonth+"/"+temp[0]+"/"+temp[2] );

        // Is this a valid Date
        if(!(isDate(testIsDate))) {
            returnSuccess = 0;
        } else if
        // Check to see if this date is greater then today.
        (!(testDate.getTime() > (new Date().getTime()))) {
            //return Failure zero is a failure.
            returnSuccess = 0;
            alertstring = alertstring + 'Expiration must be in the future. \n';
        }

    // Return the Success or Failure of the Date Format Validation
    return returnSuccess;

} 

```

Answer: 
The following section of your code isn't quite right:

```
var testDate = new Date ( temp[1]+" "+temp[0]+", "+temp[2] );
var testMonth=testDate.getMonth()+1;
if  (testMonth<10)
{
   testMonth = "0"+testDate.getMonth();   // change this line
} 

```

When you initialise `testMonth` you remember to add 1 because `.getMonth()` returns a zero-based month, but then inside your if test you use `.getMonth()` again without adding 1. You should change that to `testMonth = "0" + testMonth;`.

(Also, not the problem, but when you create `temp` there is no point initialising it to a new array when on the next line you assign it to something else.)

Sorry, I have to go so I don't have time to look for any other issues in your code.
How your `isDate` looks?
I've checked the following (with `testMonth = "0" + testMonth` change):

```
document.write( ""+ValidateFutureDate("---","20 Jan 2013"));
document.write( ""+ValidateFutureDate("---","20 jan 2013"));
document.write( ""+ValidateFutureDate("---","20 JAN 2013"));
document.write( ""+ValidateFutureDate("---","2 Jan 2013"));
document.write( ""+ValidateFutureDate("---","30 Jan 2013"));
document.write( ""+ValidateFutureDate("---","20 feb 2013"));
document.write( ""+ValidateFutureDate("---","20 jun 2013"));

```

with

```
function isDate(date){
   return true;
}

```

and it prints 1 seven times (Firefox/Opera).