• java验证码前台技术


    //下面是在前台jsp页面不用导工具的情况下制作的验证码的基本代码 

    $(function(){
       //创建验证码
        createCode();
        jQuery.validator.addMethod(
          "IsName",
          function(value){
            var reg = /^w{4,20}$/
            return reg.test(value)
          },
        "this is check username"
    );
    //制作验证码
    var code;
    function createCode() {
      code = "";
      var codeLength = 6; //验证码的长度
      var checkCode = document.getElementById("checkCode");
      var codeChars = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
      'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
      'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); //所有候选组成验证码的字符,当然也可以用中文的
       for (var i = 0; i < codeLength; i++)
        {
          var charNum = Math.floor(Math.random() * 52);
          code += codeChars[charNum];
        }
       if (checkCode)
        {
          checkCode.className = "code";
          checkCode.innerHTML = code;
        }
     }
    //验证验证码
    function deng()
    {
      var inputCode = document.getElementById("inputCode").value;
      if (inputCode.length <= 0)
       {
        $("#check").html("");
        $("#check").append("<b>请输入验证码</b>");
       }
      else if (inputCode.toUpperCase() != code.toUpperCase())
       {
        $("#check").html("");
        $("#check").append("<b>验证码输入有误</b>");
        $("#login").attr("disabled","disabled");
       }
      else

       {
        $("#check").html("");
        $("#check").append("<b>验证码正确</b>");
        $("#login").removeAttr("disabled");
       }

    }

    }

    //下面是在调用实现的方法

      <div onload="createCode()" class="col-md-8 con-name">
        <form id="form1" runat="server" onsubmit="validateCode()">
      <div>
        <table border="0" cellspacing="5" cellpadding="5" >
          <tr>
            <td><div style="margin-left: 30px;color: #CD8162" id="checkCode" onclick="createCode()" ></div></td>  
          </tr>
          <tr>
            <td><input style="float:left;" type="text" id="inputCode" onmouseout="validateCode()" /></td> 

          </tr>
          <tr>
    <td id="check" align="center"></td></tr>

        </table>
      </div>

     

     

     

     

     

  • 相关阅读:
    Java 数组
    【转】Centos 设置IP地址的几种方式
    【转】CentOS 使用yum命令安装出现错误提示”could not retrieve mirrorlist http://mirrorlist.centos.org ***”
    【转】CentOS图形界面的开启与关闭
    【转】linux Centos 6.5 安装桌面环境GNOME
    VirtualBox 更改主机和虚拟机之间的鼠标切换热键
    【转】Virtualbox虚拟机配置安装CentOS 6.5图文教程
    0622 python 基础05
    0617 python 基础04
    0610 python 基础03
  • 原文地址:https://www.cnblogs.com/zhouyingming/p/5943368.html
Copyright © 2020-2023  润新知