求一段判断日期格式是否正确的javascript str.search(/^\d{4}-\d{2}-\d{2}$/)比大小直接用字典比较就可以了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function isValidDate(dateStr){// Checks for the following valid date formats://MM/dd/yyyy var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; var matchArray = dateStr.match(datePat); // is the format ok? if (dateStr=="") { alert("日期没填"); return false; } if (matchArray == null) { alert("日期格式无效"); return false; } month = matchArray[1]; // parse date into variables day = matchArray[3]; year = matchArray[4]; if (month < 1 || month > 12) { // check month range alert("‘月’的有效范围必须在1至12之间"); return false; } if (day < 1 || day > 31) { alert("‘日’的有效范围必须在1至31之间"); return false; } if ((month==4 || month==6 || month==9 || month==11) && day==31) { alert(month+"月不能有31天!") return false } if (month == 2) { // check for february 29th var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day==29 && !isleap)) { alert(year+"年二月不能有"+ day + "天"); return false; } } return true; // date is valid} php 根据输入 开始时间 结束时间 获取数据库中表中记录 php 新手问题 服务器禁用了exec,system,passthru,popen,pclose,shell_exec,proc_open,curl_exec,multi_exe php post提交。问题 mysql gui tools如何导出sql文件 请教一下,关于正则preg_match_all的 怎么不弹出下载窗口而直接显示图片内容 这个错误识什么意思?? *****我觉得可结分的帖子***** 高分请教!一个php解析问题?? 何处得到phpUnit 怎样判断insert是否成功呢?
{
// Checks for the following valid date formats:
//MM/dd/yyyy
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?
if (dateStr=="")
{
alert("日期没填");
return false;
}
if (matchArray == null)
{
alert("日期格式无效");
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12)
{ // check month range
alert("‘月’的有效范围必须在1至12之间");
return false;
}
if (day < 1 || day > 31)
{
alert("‘日’的有效范围必须在1至31之间");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31)
{
alert(month+"月不能有31天!")
return false
}
if (month == 2)
{ // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap))
{
alert(year+"年二月不能有"+ day + "天");
return false;
}
}
return true; // date is valid
}