检查字段:
checkFields = function() {
var colCheck = 0;
var colArray = [];
var colDupArray = [];
var iDate = $("check_date").value;
if(iDate.length > 0) {
var a = iDate.split("/");
if(isValidDate(a[0],a[1]-1,a[2]) == false){
alert("You have entered an invalid date. Please amend!");
return false;
}
验证:
isValidDate = function(day,month,year) {
var dteDate;
dteDate=new Date(year,month,day);
var day = dteDate.getDate();
var month = dteDate.getMonth() + 1;
var year = dteDate.getFullYear();
var formatted =
(day < 10 ? "0" : "") + day + "/" +
(month < 10 ? "0" : "") + month + "/" +
year;
return
+day === dteDate.getDate() &&
+month === dteDate.getMonth() &&
+year === dteDate.getFullYear();
}
问题是我的代码正在接受诸如“03.06.2012”之类的日期,而我只希望它接受数字之间的斜线。
当我只想要一个四位数的年份时,它也接受“03/06/12”。
有任何想法吗?