邮箱验证格式

来源:互联网 发布:人工智能 dsp fpga 编辑:程序博客网 时间:2024/04/27 15:01
<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() == '') {
                    $('span').text('邮箱不能为空');  
                    $(this).focus();
                }
                else {
                    if (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test($(this).val()) == false) {


                        $('span').text('邮箱格式不正确,请重新输入');
                        $(this).focus();
                    }
                    else {
                        $('span').text('');
                        $('span').append('<img src=images/onSuccess.gif/>');
                        state = true;
                    }


                }


            })
        })
    </script>
</head>
<body>
    <input id="txtEmail" type="text" value="输入邮箱" class="txtbackcolor" /><span></span>
</body>
原创粉丝点击