我正在尝试在不使用正则表达式的情况下编写 javascript 日期格式验证。当我输入日期 26/02/2013 时,我的警报值为 Wed Sep 2 2093,错误消息日期不是有效格式
任何帮助将不胜感激
function CheckDateFormat(StartDateform)
{
var StartDateform= document.getElementById('tblTarget').rows[1].cells[StartDate].getElementsByTagName('input')[0].value;
spl = StartDateform.split("/");
var testDate=new Date(spl[2],spl[0]-1,spl[1]);
year= testDate.getFullYear();
month = testDate.getMonth()+1;
day= testDate.getDate();
alert ("the date value is "+ " "+ testDate);
if (day!==spl[1] || month!==spl[0] || year!==spl[2])
{
alert ("the date value is "+ " "+ testDate);
alert(StartDateform + " " + "Is an Invalid Date. Please use the format 'MM/DD/YYYY'");
return false;
}
return true;
}
function Submit()
{
if(CheckDateFormat())
{
$('button_submit').click();
alert('New rate submitted');
}
}