|
經(jīng)常在ASP里面碰到要求用戶(hù)輸入日期,比如生日,那么如何知道他輸入的值是否有效呢?比如輸入2月,則肯定沒(méi)有30,31號(hào);又如她要是輸入4月,那么肯定沒(méi)有31號(hào),等等..... 下面是我碰到時(shí)的解決方案,在ASP中實(shí)現(xiàn): Tyear=parseInt(<%=year(date)%>); Tmonth=parseInt(<%=month(date)%>); Tday=parseInt(<%=day(date)%>); Tdate= Tyear*10000+Tmonth*100+Tday; Fyear=parseInt(document.register.birthyear.value); Fmonth=parseInt(document.register.birthmonth.value); Fday=parseInt(document.register.birthday.value); Fdate=(Fyear+18)*10000+Fmonth*100+Fday; if(Fyear==0 Fmonth==0 Fday==0){ alert("請(qǐng)選擇您的出生日期。"); document.register.birthyear.focus(); return false; } else if(Fdate>Tdate){ alert("對(duì)不起,您未滿(mǎn)十八歲。"); document.register.birthyear.focus(); return false; } else { theDate = new Date(Fyear,Fmonth,0); if (Fday > theDate.getDate ()) { window.alert ("出生日期輸入錯(cuò)誤!"); return false; } }
|
溫馨提示:喜歡本站的話(huà),請(qǐng)收藏一下本站!