js 校验验证码 知识点
驗(yàn)證碼action類
request.getSession().setAttribute("rand", p_w_picpath.getSRand());
<input type="text" name="imag" id="imagnum">//驗(yàn)證碼輸入框
<input type="hidden" id="code" value="<%=session.getattribute("rand") %>">//action中生成的驗(yàn)證碼
<input type="submit" value="登陸" ?type="reset" value="取消">
js代碼:function check() {
var imagnum = $("#imagnum").val();
var rands = $("#code").val();
alert(rands);
var message;
if (imagnum != rands) {
message = "驗(yàn)證碼錯(cuò)誤,請重新填寫!"
$("#checkcode").html(message);
}
}
判斷不超過5000個(gè)字符
<script language="javascript">
{
var str=document.getElementById("txt").value
var txtLength
obj=str.match(/[^\x00-\xff]/g)
if(obj!=null)
{
txtLength=obj.length+str.length;
}
else
{
txtLength=str.length;
}
if(txtLength>5000)
{
alert("超過限制!")
return false
}
}
</script>
<form method="post" action="" οnsubmit="return check()">
<textarea id="txt"></textarea>
<input type="submit" value="提交">
</form>不錯(cuò)js判漢字function DataLength(fData)
? ? ? ? ? ?{
? ? ? ? ? ?var intLength=0
? ? ? ? ? ?for (var i=0;i<fData.length;i++)
? ? ? ? ? ?{
? ? ? ? ? ? ? if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255))
? ? ? ? ? ? ? ?intLength=intLength+2
? ? ? ? ? ? ? else
? ? ? ? ? ? ? ?intLength=intLength+1
? ? ? ? ? ?}
? ? ? ? ? ?if(intLength>5000){
? ? ? ? ? ? ? document.getElementById("txt").disabled="disabled"; ? ? ? ?//當(dāng)超過5000字時(shí)候,把textarea標(biāo)簽設(shè)為不可寫。
? ? ? ? ? ? ? ? }
? ? ? ? ? ?}
轉(zhuǎn)載于:https://blog.51cto.com/2197042/1220840
總結(jié)
以上是生活随笔為你收集整理的js 校验验证码 知识点的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sysbench对数据库的性能测试
- 下一篇: spring InitializingB