<script>
function check(ss){
if (/\-0/.test(ss)) return false;
re=/^(\d{2})\-(\d{1,2})\-(\d{1,2})$/.exec(ss);
if (!re) return false;
return ((re[2]>0) && (re[2]<13) && (re[3]>0) && (re[3]<32))
}alert(check("99-08-01"))
alert(check("99-8-1"))
</script>
function check(ss){
if (/\-0/.test(ss)) return false;
re=/^(\d{2})\-(\d{1,2})\-(\d{1,2})$/.exec(ss);
if (!re) return false;
return ((re[2]>0) && (re[2]<13) && (re[3]>0) && (re[3]<32))
}alert(check("99-08-01"))
alert(check("99-8-1"))
</script>
function strDate(str){
var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
var r = str.match(reg);
if(r==null)return false;
var d= new Date(r[1], r[3]-1,r[4]);
var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate()
return newStr==str
}
alert(strDate("2002-1-31"))
alert(strDate("2002-2-31"))
alert(strDate("2002-1-41"))
</script>
/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$//^ 和 $/是否为开始结尾符号。(\d{1,4})表示4个整数数字?
(-|\/)表示- 或者 /?
(\d{1,2}) 表示2个整数数字?
\2表示什么?
通过匹配,r获得一个4元的数组?从左往右为r[1],r[2],r[3],r[4]?
如此,r[3]就应该为月份,为何要减1 if(r==null)return false;
var d= new Date(r[1], r[3]-1,r[4]);
var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate()
return newStr==str