ITeye博客

有关jQuery中表单验证的问题

ztfjava · 2010-09-15 06:05 · Java · Web前端 · Markdown

随着jquery的流行越来也多的网站开始使用jquery来做网站的有特效

    为了减轻服务器端的压力 为了达到CS的那种高效 ,减轻网络流量

    对表单的验证 放在了客户端。

age:这是jsp网页其中的表单部分

下面是jquery的代码

     var passwd1;

$(document).ready(function(){ $(".tabin input").each(function(index){

            $(this).focus(function(){
            //当光标定位是改变输入框的颜色
            $(this).css("border-color","#FF0000");
            $(this).next("div").html("");
           
            }).blur(function(){
                if(index==0){
                    var str = $(this).val();
                    var reg_exception =/{1,}/;
                    var result = reg_exception.test(str);
                    if(result){
                    $(this).css("border-color","#54585B")
                    }else{
                        $(this).next("div").html("请输入中文 或英文 或数字");
                        $(this).css("border-color","#FF000000");
                        $(this).val("");
                    }
                }
                if(index==1){alert("与用户名的输入框验证相似")}
                if(index==2){alert("与用户名的输入框验证相似")}
                if(index==3){
                    var reg_exception =/^{6,}$/;
                    passwd1 = $(this).val();
                    var result =reg_exception.test(passwd1);
                    if(result){
                    $(this).css("border-color","#404040");
                    }else{
                        $(this).css("border-color","#D70402");
                        $(this).next("div").html("密码必须为6-20为的数字或大小写字母");
                        $(this).val("");
                    }
                }
                if(index==4){
                    var reg_exception =/^{6,}$/;
                    var str2 = $(this).val();
                    var result =reg_exception.test(str2);
                    if(result){
                        if(passwd1==str2){
                        $(this).css("border-color","#404040");
                        }else{
                            $(this).css("border-color","D70402");
                            $(this).next("div").html("两次输入的密码不一致!请重新输入");
                            $(this).val("");
                        }
                    }else{
                        $(this).css("border-color","#404040");
                        $(this).next("div").html("密码必须为6-20为的数字或大小写字母");
                        $(this).val("");
                    }
                }
            });
           
   
    });

});

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。