var oRegA=/^(\d{4})[-\/](\d{1,2})[-\/](\d{1,2})$/ig
var sDate = "1022-22-2"
var bOk = false;
do{
if(!oRegA.test(sDate)) break;
var nVal = parseInt(RegExp.$1)
if(nVal<1970 || nVal>3000) break;
nVal = parseInt(RegExp.$2)
if(nVal<1 || nVal>12) break;
nVal = parseInt(RegExp.$3)
if(nVal<1 || nVal>31) break;
bOk=true;
}while(false)
if(!bOk)alert("时间错误")
(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/(19|20)[0-9]{2}
C# code:
time.ToString("dd/MM/yyyy", DateTimeFormatInfo.InvariantInfo);
写正则表达式
\b([0-2]{0,1}[0-9]{1}|3{1}[0-1]{1})\b\\{1}\b(0{0,1}[0-9]{1}|1{1}[0-2]{1})\b\\{1}[0-9]{4}
如果只是验证格式的话,不知道这样写有没有问题?