JS利用正则,判断是否是邮箱,邮编

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
	<meta charset="utf-8" />
    <script type="text/javascript">
        window.onload = function () {
            var zhengce = /^[0-9]{6}$/;
            var emailZC = /([-a-zA-Z_0-9.]+)@([-a-zA-Z0-9_]+(\.[a-zA-Z]+)+)/;
            var txtObj = document.getElementById('txt1');
    
            document.getElementById('btn1').onclick = function () {
                var b = zhengce.test(txtObj.value);
                alert(b);
            }
            document.getElementById('btn2').onclick = function () {
                var b = emailZC.test(txtObj.value);
                alert(b);
            }
        }
       
    </script>
</head>
<body>
    <input type="text" id="txt1" />
    <input type="button" id="btn1" value="判断是否是邮编"/>
    <input type="button" id="btn2" value="判断是否是邮箱" />
</body>
</html>

评论