一瞬儿光
<script type="text/javascript">
var a = "20161014";
var b = "2016 10 14";
var c = "2016-10-14";
var d = "2016/10/14";
var e = "2016.10.14";
var f = "10-2016-14";
var g = "14 10 2016";
var h = "2016-14-10";
var i = "2016114-10";
function checkDate(date) {
var reg = new RegExp("^(((\\d{4})([-|/|\\.|\\s]?\\d{1,2}){2})|((\\d{2})([-|/|\\.|\\s]{1}\\d{4})([-|/|\\.|\\s]{1}\\d{2}))|((\\d{2})([-|/|\\.|\\s]{1}\\d{2})([-|/|\\.|\\s]{1}\\d{4})))$");
return date.match(reg);
}
console.log(checkDate(a));
console.log(checkDate(b));
console.log(checkDate(c));
console.log(checkDate(d));
console.log(checkDate(e));
console.log(checkDate(f));
console.log(checkDate(g));
console.log(checkDate(h));
console.log(checkDate(i));
</script>