This function will edit dates in the format MM/DD/CCYY or MMDDCCYY and returns in the format MM/DD/CCYY. You need only pass the text field object and text field value. It will validate characters, months and number of days in a month. If the entry is invalid it returns focus to that field. If the field is left blank it allows the user to lose focus. Hope this helps.
function isDate (objname, DateField) {
var ValidDigits = "0123456789/";
var allNum = "";
var InvalidDigit = "";
var mmddccyy = DateField.replace(/ /gi,""

;
var month = mmddccyy.substring(0,2);
var day = mmddccyy.substring(3,5);
var year = mmddccyy.substring(6,10);
var today = new Date();
month = ((!month) ? today.getMonth():month-1);
var test = new Date(year,month,day);
for (i = 0; i < DateField.length; i++)
{
ch = DateField.charAt(i);
for (j = 0; j < ValidDigits.length; j++)
{
if (ch == ValidDigits.charAt(j))
{
break;
}
}
if (j == ValidDigits.length)
{
InvalidDigit = 'YES';
break;
}
}
if (trim(DateField).length == 8 && DateField / DateField == 1)
{
mmddccyy = DateField.substring(0,2);
mmddccyy += '/';
mmddccyy += DateField.substring(2,4);
mmddccyy += '/';
mmddccyy += DateField.substring(4,8);
mmddccyy = mmddccyy.replace(/ /gi,""

;
month = mmddccyy.substring(0,2);
day = mmddccyy.substring(3,5);
year = mmddccyy.substring(6,10);
month = ((!month) ? today.getMonth():month-1);
var test = new Date(year,month,day);
}
if (trim(mmddccyy).length == 0)
{
return mmddccyy;
}
else
if (InvalidDigit == 'YES')
{
alert("Invalid Date : " + DateField + "\nPlease Enter Valid Date : Format MM/DD/CCYY"

;
objname.focus();
return "";
}
else
if (mmddccyy / mmddccyy == 1 || trim(year).length != 4)
{
alert("Invalid Date : " + DateField + "\nPlease Enter Valid Date : Format MM/DD/CCYY"

;
objname.focus();
return "";
}
else
if ( (month == test.getMonth()) && (day == test.getDate()) )
{
return mmddccyy;
}
else
{
alert("Invalid Date : " + DateField + "\nPlease Enter Valid Date : Format MM/DD/CCYY"

;
objname.focus();
return "";
}
}