使用针对MM / dd / yyyy hh:mm:ss格式的javascript验证TextBox日期时间字段

问题描述:

var chkdate = document.getElementById(<%= txtFromDate.ClientID%>)。value

if(document.getElementById(<%= txtFromDate.ClientID%> )。value ==){

alert(请输入日期.. !!)

hh.date_slot.focus();

返回false;

}

else if(!chkdate.match(/ ^(0 [1-9] | 1 [012])[\\ \\-\ /。](?:( 0 [1-9] | [12] [0-9] | 3 [01])[\- \ /。](19 | 20)[0-9 ] {2})$ /)){

alert('日期格式错误');

hh.date_slot.focus();

返回false;

}



以上功能验证MM / dd / yyyy格式..



我需要及时验证.. MM / dd / yyyy hh:mm:ss格式......

我想在哪里做出改变..? ?\



请帮帮我。



谢谢

var chkdate = document.getElementById("<%=txtFromDate.ClientID %>").value
if (document.getElementById("<%=txtFromDate.ClientID %>").value == "") {
alert("Please enter the Date..!!")
hh.date_slot.focus();
return false;
}
else if (!chkdate.match(/^(0[1-9]|1[012])[\-\/.](?:(0[1-9]|[12][0-9]|3[01])[\- \/.](19|20)[0-9]{2})$/)) {
alert('date format is wrong');
hh.date_slot.focus();
return false;
}

The above function is validating MM/dd/yyyy format..

I need to validate with time also.. MM/dd/yyyy hh:mm:ss format...
Where i want to make the change..??\

Please help me.

Thanks

/)){

alert('日期格式错误');

hh.date_slot.focus();

返回false;

}



以上功能验证MM / dd / yyyy格式..



我需要及时验证.. MM / dd / yyyy hh:mm:ss格式......

我想做出改变的地方。 。?? \



请帮帮我。



谢谢
/)) {
alert('date format is wrong');
hh.date_slot.focus();
return false;
}

The above function is validating MM/dd/yyyy format..

I need to validate with time also.. MM/dd/yyyy hh:mm:ss format...
Where i want to make the change..??\

Please help me.

Thanks


我猜你从其他地方得到了这个功能?

我说的原因是因为如果你自己写的,甚至停下来研究代码你就可以找出你需要改变的东西而不需要在这里发帖。



我建议你在这里查看这行代码:



I'm guessing that you got this function from somewhere else?
The reason I say that, is because if you wrote it yourself, or even stopped and studied the code you would be able to identify what you need to change without the need to post on here.

I suggest you look at this line of code here:

(!chkdate.match(/^(0[1-9]|[12][0-9]|3[01])[\- \/.](?:(0[1-9]|1[012])[\-\/.](19|20)[0-9]{2})


/))



因为这是正在做的行当前比较,你需要做的就是将月部分移动到日部分的位置,反之亦然。


As this is the line that is doing the current comparison, all you need to do is move the "month" section to where the "day" section is and vice versa.