js判斷輸入日期是否在當前日期之前
阿新 • • 發佈:2019-02-17
關於日期的格式驗證可以使用WdatePicker進行輸入即可驗證。
下面是js驗證輸入日期是否在當前日期之前的程式碼:
function checkTime() { var check = 0; var nowDate = new Date(); var date = nowDate.getFullYear()+"年"+(nowDate.getMonth()+1)+"月"+nowDate.getDate()+"日"; var input_time = $('#time').val(); var time_split = new Array(); time_split = input_time.split("-"); if(nowDate.getFullYear() < time_split[0]) { check = 0; alert('當前僅能錄入'+date+'之前的資料'); document.getElementById("time").select(); } else if(nowDate.getFullYear()==time_split[0] ) { if(nowDate.getMonth()+1 < time_split[1]) { check = 0; alert('當前僅能錄入'+date+'之前的資料'); document.getElementById("time").select(); } else if(nowDate.getMonth()+1 == time_split[1]) { if(nowDate.getDate() <= time_split[2]) { check = 0; alert('當前僅能錄入'+date+'之前的資料'); document.getElementById("time").select(); } else { check = 1; } } else { check = 1; } } else { check = 1; } return check; }