码迷,mamicode.com
首页 > Web开发 > 详细

html前端登录验证

时间:2019-06-08 16:20:38      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:sub   style   gre   erro   pwd   ext   text   lang   rem   

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="../jquery-1.7.2/jquery.min.js"></script>
    <script>
    $(function(){
        //onblur: 光标离开控件,会触发onblur事件
        $("#email").blur(function(){
            var re = /^\w+@\w+(\.\w+){1,3}$/;    
            if ( $(this).parent().find( "span" ).length > 0 ) {
                $(this).parent().find( "span" ).remove();    
            }
            if ( re.test( $(this).val() ) ) {
                $(this).after( "<span class=‘ok‘>格式正确</span>" );
            }else {
                $(this).after( "<span class=‘error‘>格式错误</span>" );
            }
        });
        $("#pwd").blur(function(){
            var re = /^\w{6,20}$/;
            if ( $(this).parent().find( "span" ).length > 0 ) {
                $(this).parent().find( "span" ).remove();    
            }
            if ( re.test( $(this).val() ) ) {
                $(this).after( "<span class=‘ok‘>格式正确</span>" );
            }else {
                $(this).after( "<span class=‘error‘>格式错误</span>" );
            }
        });
        $("#reg :submit").click(function(){
            $("#email").trigger("blur");
            $("#pwd").trigger("blur");
            if ( $("#reg").find(".error").length > 0 ) {
                return false;
            }
        });
    });    
    </script>
    <style>
    .ok {
        color:green;
    }
    .error {
        color:red;
    }
    </style>
</head>
<body>
    <form action="http://www.baidu.com" method="get" id="reg">
        <p class=emailParent>
            邮箱: <input type="text" name="email" id="email">            
        </p>
        <p>
            密码: <input type="text" name="pwd" id="pwd">
        </p>
        <p>
            <input type="submit" id="submit" value="注册" >
        </p>
    </form>    
</body>
</html>

 

html前端登录验证

标签:sub   style   gre   erro   pwd   ext   text   lang   rem   

原文地址:https://www.cnblogs.com/MoonWorship/p/10990931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!