使用正则表达式判断是否是合法的邮箱

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
	<meta charset="utf-8" />
</head>
<body>
    请输入邮箱:<input id="txtEmail"/>
    <input type="button" id="btnJudge" value="判断邮箱是否合法"/>
    <script type="text/javascript">
        window.onload = function () {
            document.getElementById('btnJudge').onclick = function () {
                //得到用户输入的邮箱
                var strEmail = document.getElementById('txtEmail').value.trim();
                //创建正则表达式
                var reg = /^\w+@\w+(\.\w+)+$/;
                var result = reg.test(strEmail);
                alert(result);
            };          
        };
    </script>
</body>
</html>

你可能感兴趣的:(Javascript,JQuery练习)