客户端脚本验证码总结

80酷酷网    80kuku.com

   function Jtrim(str)  //去空隔函数
{

        var i = 0;
        var len = str.length;
        if ( str == "" ) return( str );
        j = len -1;
        flagbegin = true;
        flagend = true;
        while ( flagbegin == true && i< len)
        {
           if ( str.charAt(i) == " " )
                {
                  i=i+1;
                  flagbegin=true;
                }
                else
                {
                        flagbegin=false;
                }
        }

        while  (flagend== true && j>=0)
        {
            if (str.charAt(j)==" ")
                {
                        j=j-1;
                        flagend=true;
                }
                else
                {
                        flagend=false;
                }
        }

        if ( i > j ) return ("")

        trimstr = str.substring(i,j+1);
        return trimstr;
}

        function isNumber(s) //数字判断函数
        {
                var digits = "0123456789";
                var i = 0;
                var sLength = s.length;

                while ((i < sLength))
                {
                        var c = s.charAt(i);
                        if (digits.indexOf(c) == -1) return false;
                        i++;
                }

                return true;
        }
function isemail (s)//验证E-MAIL格式函数
{
        
        if (s.length > 100)
        {
                window.alert("email地址长度不能超过100位!");
                return false;
        }

         var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$"
         var re = new RegExp(regu);
         if (s.search(re) != -1) {
               return true;
         } else {
               window.alert ("请输入有效合法的E-mail地址 !")
               return false;
         }
}
//判断是否中文函数
function ischinese(s){
var ret=true;
for(var i=0;i<s.length;i++)
ret=ret && (s.charCodeAt(i)>=10000);
return ret;
}
//--------------------------------------------------------------------------------
function ismit()//判断radio是否没有选择函数
{
        var count=0;
        for (ii=0;ii<myform.elements.length;ii++)
        {
                if (myform.elements[ii].type=="radio" && myform.elements[ii].checked==true)
                {
                                count++;
                }
        }
          
         if (Jtrim(document.myform.user_name.value)=='') {
                window.alert ("请输入您的队员名 !")
                myform.user_name.focus();
                return false;
        }
       if(ischinese(document.myform.user_name.value)){
       window.alert("请输入英文队员名")
       myform.user_name.focus();
                return false;
}
        
    }
      if (Jtrim(myform.user_pass1.value)=="" || myform.user_pass1.value.length < 4)
     {
         alert("您的密码不能为空且不能少于4位数!");
         myform.user_pass1.focus();
         myform.user_pass1.select();
         return false;
     }
     if (Jtrim(myform.user_pass2.value)=="" || myform.user_pass2.value.length < 4)
     {
         alert("您的确认密码不能为空且不能少于4位数!");
         myform.user_pass2.focus();
         myform.user_pass2.select();
         return false;
     }
     if (myform.user_pass1.value!=myform.user_pass2.value)
     {
                 alert("您两次输入的密码不相同,请重新输入!");
                 myform.user_pass1.value="";
                 myform.user_pass2.value="";
                 myform.user_pass2.focus();
                 return false;
     }
  
        if (!isNumber(document.myform.user_qq.value))
        {
          window.alert ("QQ号码应该是数字,请重新输入!");
          myform.user_qq.focus();
          myform.user_qq.value='';
         return false;
     }
        if (Jtrim(document.myform.user_email.value)==''){
        window.alert("请填写您经常使用的一个邮箱!");
        myform.user_email.focus();
        return false;
     }
     if (!isemail(document.myform.user_email.value))
     {
         myform.user_email.focus();
         return false;
     }
     if (myform.user_question.value==0)
     {
         alert("请选择一个密码提示问题");
         myform.user_question.focus();
         return false;
     }
     
    return true;
}

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: