您好我目前堅持如何分割我的正則表達式日期,然後測試是否輸入日期是過去。如果是這樣我想提醒一下。需要幫助驗證日期是否過去使用javascript
我知道我需要如何拼接我的正則表達式,但我不確定如何做到這一點,任何幫助將不勝感激。下面是我的腳本到目前爲止它是一個相當長的正則表達式,但它涵蓋了所有內容,包括閏年,但就像我說我知道需要通過substr或splice將其分解。
//start of datefield
var dateformat=/^(?:(?:31\/(?:0[13578]|1[02])|(?:29|30)\/(?:0[13-9]|1[012])|(?:0[1-9]|1\d|2[0-8])\/(?:0[1-9]|1[0-2]))\/[2-9]\d{3}|29\/02\/(?:[2-9]\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[3579][26])00))$/;
if (!date.match(dateformat))
{
alert("format incorrect use dd/mm/yyyy make sure you are entering correct days to the month remember 30 days have september, april, june & november, only 28 days in february unless leap year next is 2016");
return false;
}
//end date field
我的建議是:溝是正則表達式。檢查我的答案在這裏,這應該有助於http://stackoverflow.com/questions/11218181/best-way-to-validate-date-string-format-via-jquery/11218271#11218271 – elclanrs
爲什麼你需要使用正則表達式? – Blender
使用他人的工作! http://momentjs.com/ –