日期:2014-05-16 浏览次数:20347 次
有日期和时间的:2013-10-12 08:20:35 /^\d{4}(-\d{1,2}){2}\s\d{1,2}(:\d{1,2}){2}$/
只有日期的:2013-10-12 /^\d{4}(-\d{1,2}){2}$/
只有时间的:12:20:35 /^\d{1,2}(:\d{1,2}){2}$/
var rx = /^((\d{4}(-\d{1,2}){2} )?(\d{2}(:\d+){2})
------解决方案--------------------
\d{4}(-\d{1,2}){2})$/
var t1 = '2013-10-12 08:20:35';
var t2 = '2013-10-12';
var t3 = '08:20:35';
var t4 = '08:20';
var t5 = ' 08:20:20';
var t6 = '2013-10-12 ';
alert(rx.test(t1))
alert(rx.test(t2))
alert(rx.test(t3))
alert(rx.test(t4))
alert(rx.test(t5))
alert(rx.test(t6))