下面提供的是一款根据日期格式来用正则判断当前日期是否合法哦。
function(op, formatString){
formatString = formatString || "ymd";
var m, year, month, day;
switch(formatString){
case "ymd" :
m = op.match(new RegExp("^((\d{4})|(\d{2}))([-./])(\d{1,2})\4(\d{1,2})$"));
if(m == null ) return false;
day = m[6];
month = m[5]*1;
year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
break;
case "dmy" :
m = op.match(new RegExp("^(\d{1,2})([-./])(\d{1,2})\2((\d{4})|(\d{2}))$"));
if(m == null ) return false;
day = m[1];
month = m[3]*1;
year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));
break;
default :
break;
}
我们判断了ydm,dym几种格式的日期合法性哦。
时间: 2024-09-29 02:56:35