|
应该怎么做,我是在form.submit 里写的。 怎么把document.form.year.value 的值转成int型啊??? |
|
|
|
cint(value)
可我认为没有必要。 |
|
|
if (isInvalidDate(document.form_register.birthday.value,"-"))
{ alert("您的出生年月填写错误,格式是1980-1-1"); document.form_register.birthday.focus(); return false; } |
|
|
那要是我是分3个输入框输入的呢,三个字段怎么加在一起????
|
|
|
在JAVASCRIPT里面CINT是没用的,在script里面数据类型转换的功能本来就比较弱,所以教你一个简单的字符串转数字的方法:(document.form.year.value)*1
你要把年月日加在一起就用+啊: document.form.year.value + "-" + document.form.month.value + "-" + document.form.day.value 这样不就行啦~!然后转换成日期,用new date运算就行了 |
|
|
晕,提交过后在下一个页面中加在一起不就OK了。
<% birthday=request("year") & "/" &request("month")& "/" & request("day") %> 或者是: <% birthday=request("year") & "-" &request("month")& "-" & request("day") %> 不过你在上一个页面中提交之前,要用javascript判断,年,月,日。是否在规定的范围之内。 <script> function formChecked(obj) { if(obj.year.value<1900||obj.year.value>9999) { alert("生日的年份应在1900和9999之间"); obj.year.focus(); return false; } if(obj.month.value<1||obj.month.value>12) { alert("生日的月份应在1和12之间"); obj.month.focus(); return false; } if(obj.day.value<1||obj.day.value>31) { alert("生日的年份应在1和31之间"); obj.day.focus(); return false; }//注意:还有月份不同,每月的天数也是不同的,有点烦,我就不写了,你自己想办法判断吧。 return true; } |
|
|
反正一句话,在script里做这样的判断确实太难为script了,我也建议你在提交后用ASP来判断
|
|
|
应该可以用JS做日历都行何况一个小小的验证呢
由于我没在公司资料库不在 等下次给你一个完美的答案. |
|
|
等待同路给一个完美的答案。:)
|
|
|
好不容易给你写完了,看看合不合适
<form name="form2" method="post" action="" onSubmit="return check()"> <input name="YYYY" type="text" id="YYYY" size="6"> <input name="MM" type="text" id="MM" size="6"> <input name="DD" type="text" id="DD" size="6"> <input type="submit" name="Submit" value="Submit"> </form> <script language="JavaScript"> function check() { var dates=document.form2.YYYY.value+"-"+document.form2.MM.value+"-"+document.form2.DD.value if (isInvalidDate(dates,"-")) { alert("您的日期添写错误!"); return false; } return true; } function isInvalidDate(theDate,separator){ default_style=1 if (theDate.length>10 || theDate.length<8) return true idx1=theDate.indexOf(separator) if (idx1==-1) return true idx2=theDate.indexOf(separator,idx1+1) if (idx2==-1) return true if (isInvalidDate.arguments.length>2) default_style=isInvalidDate.arguments[2] if (default_style<1 || default_style>9){ alert("日期填写有误") return true } if (default_style==1){ theYear=theDate.substring(0,idx1) theMonth=theDate.substring(idx1+1,idx2) theDay=theDate.substring(idx2+1) } if (default_style==2){ theMonth=theDate.substring(0,idx1) theDay=theDate.substring(idx1+1,idx2) theYear=theDate.substring(idx2+1) } if (theDay.length>2) return true if (parseYMD(theYear,theMonth,theDay)>0) return true else return false } function parseYMD(theYear,theMonth,theDay) { theYear=parseNum(theYear) theMonth=parseNum(theMonth) theDay=parseNum(theDay) if ((theYear < 1900) || (theYear > 3000)){ return 1 } if (theMonth < 1 || theMonth > 12){ return 2 } if ((theMonth==1 || theMonth==3 || theMonth==5 || theMonth==7 || theMonth==8 || theMonth==10 || theMonth==12) && (theDay <1 || theDay > 31) ){ return 3 } if ((theMonth==4 || theMonth==6 || theMonth==9 || theMonth==11) && (theDay <1 || theDay > 30) ){ return 3 } if (theYear%400==0 || (theYear%4==0 && theYear%100!=0)){ //闰年 if (theMonth==2 && (theDay <1 || theDay > 29) ) return 3 } else //平年 if (theMonth==2 && (theDay <1 || theDay > 28) ) return 3 return 0 } function parseNum(theNum){ if (theNum.substring(0,1)==0) theNum=theNum.substring(1) return theNum } </script> |
|
|
theYear mod 400=0 or ((theYear mod 4)=0 and ((theYear mod 100)<>0)
(可以400整除)或者(可以除4但不可以被100整除的) 闰年2月29天,否则 平年28天 |
|
|
theYear mod 400=0 or ((theYear mod 4)=0 and ((theYear mod 100)<>0)
(可以400整除)或者(可以除4但不可以被100整除的) 闰年2月29天,否则 平年28天 |
|
|
目前公认的闰年判断算法,满足下列二者之一,即为闰年:
① 能被4整除,但不能被100整除 ② 能被4整除,且能被400整除 |
|
|
应该没错吧?楼主搞定没有???
|
|
|
用下一个月的第一天dateadd减去一天就是这个月的最后一天,用不着计算闰年和平年
|
|
|
用vbs嘛更简单了,isDate()直接可以验证合法日期
|
|
|
我看看!!!呵呵
马上结贴 |
|