<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>42度空间-从0到1分步实现一个出生日期校验的正则表达式-年份校验</title>
</head>
<body>
<div id="main"></div>
<script>
    console.log = function(val) {
        document.getElementById("main").innerHTML += val +"<br />";
    }
    var pattern = /^(19[2-9]\d{1})|(20((0[0-9])|(1[0-8])))$/;
    //输出 false
    console.log(pattern.test("1916"));
    //输出 true
    console.log(pattern.test("2009"));
    //输出 false
    console.log(pattern.test("2022"));
</script>
</body>
</html>