日期和时间的正则表达式:时间格式是yyyy-MM-dd hh:mm:ss和MM-dd hh:mm:ss和hh:mm:ss
1个回答
展开全部
js:
var m = /(\d{4}-\d{2}-\d{2}\d{2}:\d{2}:\d{2})|(\d{2}-\d{2}\d{2}:\d{2}:\d{2})|(\d{2}:\d{2}:\d{2})/;
var s = "2012-01-23 21:08:29";
//s = "01-23 21:08:29";
//s = "21:08:29";
alert(m.test(s));
java:将上面的\d换成\\d
var m = /(\d{4}-\d{2}-\d{2}\d{2}:\d{2}:\d{2})|(\d{2}-\d{2}\d{2}:\d{2}:\d{2})|(\d{2}:\d{2}:\d{2})/;
var s = "2012-01-23 21:08:29";
//s = "01-23 21:08:29";
//s = "21:08:29";
alert(m.test(s));
java:将上面的\d换成\\d
追问
MM-dd hh:mm:ss只校验这个格式的呢?
追答
/\d{2}-\d{2}\d{2}:\d{2}:\d{2}/
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询