对邮箱的验证

来源:互联网 发布:手机测风速软件 编辑:程序博客网 时间:2024/04/26 00:46
<head>
    <title></title>
    <style type="text/css">
    .txtbackcolor
    {
        background-color:#eee;//文本框背景颜色
    }
    </style>
    <script src="jquery-1.9.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            var state = false;
            $('#txtEmail').focus(function () {
                if (state == false) {
                    $(this).val('');
                }
            })
            $('#txtEmail').blur(function () {
                if ($(this).val == '') {
                    $('#spinfo').text('邮箱不能为空')
                    $(this).focus();
                }
                else {
                    if (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test($(this).val()) == false) {
                        $('#spinfo').text('邮箱格式不正确,请重新输入');
                        $(this).focus();
                    }
                    else {
                        $('#spinfo').text('');
                        $('#spinfo').append('<img src=images/onSuccess.gif>');//输入正确显示绿色对勾
                        state = true;
                    }
                }
            })
        })
    </script>
</head>
<body>
    邮箱<input id="txtEmail" type="text" value="输入邮箱" class="txtbackcolor"/><span id="spinfo"></span><br />
    密码<input id="txtPassword" type="text" value="输入密码" class="txtbackcolor"/><span id="spinps"></span>
</body>
</html>
原创粉丝点击