| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 317 人关注过本帖
标题:请问: 这个代码限制了什么?
只看楼主 加入收藏
leaftest
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2007-8-9
收藏
 问题点数:0 回复次数:2 
请问: 这个代码限制了什么?
<script>
function regInput(reg){
var srcElem = event.srcElement
var oSel = document.selection.createRange()
var srcRange = srcElem.createTextRange()
oSel.setEndPoint("StartToStart", srcRange)
var num = oSel.text + String.fromCharCode(event.keyCode) + srcRange.text.substr(oSel.text.length)
event.returnValue = reg.test(num)
}
</script>


<input type="text" name="T2" onKeyPress="regInput(/^[\w]*$/)" >



其实就是防止登陆的时候输入一些非法字符,但实际测试的时候我发现只要输入中文后,就不能继续输入数字或英文了,但是只输入英文也可以输入数字


如: 输入 小白 再按 222 就输不进去; 输入 xiaobai 还可以跟任何数字
搜索更多相关主题的帖子: 代码 
2007-08-17 08:49
hmhz
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:30
帖 子:1890
专家分:503
注 册:2006-12-17
收藏
得分:0 
思路就是,首先判断前两位输入的是中文还是英文来进行限制是否允许输入数字

[编程论坛] ASP超级群:49158383  敲门暗号:ASP编程
龍艺博客 http://www.
2007-08-17 09:10
ayue222
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:341
专家分:0
注 册:2007-7-25
收藏
得分:0 

既然这样,为什么不在提交之后进行非法验证过滤捏?
给你个数据库防注入的程序吧 ... 看看能吧能用上...
Function Checkstr(Str)
If Isnull(Str) Then
CheckStr = ""
Exit Function
End If
Str = Replace(Str,Chr(0),"", 1, -1, 1)
Str = Replace(Str, """", "&quot;", 1, -1, 1)
Str = Replace(Str,"<","&lt;", 1, -1, 1)
Str = Replace(Str,">","&gt;", 1, -1, 1)
Str = Replace(Str, "script", "&#115;cript", 1, -1, 0)
Str = Replace(Str, "SCRIPT", "&#083;CRIPT", 1, -1, 0)
Str = Replace(Str, "Script", "&#083;cript", 1, -1, 0)
Str = Replace(Str, "script", "&#083;cript", 1, -1, 1)
Str = Replace(Str, "object", "&#111;bject", 1, -1, 0)
Str = Replace(Str, "OBJECT", "&#079;BJECT", 1, -1, 0)
Str = Replace(Str, "Object", "&#079;bject", 1, -1, 0)
Str = Replace(Str, "object", "&#079;bject", 1, -1, 1)
Str = Replace(Str, "applet", "&#097;pplet", 1, -1, 0)
Str = Replace(Str, "APPLET", "&#065;PPLET", 1, -1, 0)
Str = Replace(Str, "Applet", "&#065;pplet", 1, -1, 0)
Str = Replace(Str, "applet", "&#065;pplet", 1, -1, 1)
Str = Replace(Str, "[", "&#091;")
Str = Replace(Str, "]", "&#093;")
Str = Replace(Str, """", "", 1, -1, 1)
Str = Replace(Str, "=", "&#061;", 1, -1, 1)
Str = Replace(Str, "'", "''", 1, -1, 1)
Str = Replace(Str, "select", "sel&#101;ct", 1, -1, 1)
Str = Replace(Str, "execute", "&#101xecute", 1, -1, 1)
Str = Replace(Str, "exec", "&#101xec", 1, -1, 1)
Str = Replace(Str, "join", "jo&#105;n", 1, -1, 1)
Str = Replace(Str, "union", "un&#105;on", 1, -1, 1)
Str = Replace(Str, "where", "wh&#101;re", 1, -1, 1)
Str = Replace(Str, "insert", "ins&#101;rt", 1, -1, 1)
Str = Replace(Str, "delete", "del&#101;te", 1, -1, 1)
Str = Replace(Str, "update", "up&#100;ate", 1, -1, 1)
Str = Replace(Str, "like", "lik&#101;", 1, -1, 1)
Str = Replace(Str, "drop", "dro&#112;", 1, -1, 1)
Str = Replace(Str, "create", "cr&#101;ate", 1, -1, 1)
Str = Replace(Str, "rename", "ren&#097;me", 1, -1, 1)
Str = Replace(Str, "count", "co&#117;nt", 1, -1, 1)
Str = Replace(Str, "chr", "c&#104;r", 1, -1, 1)
Str = Replace(Str, "mid", "m&#105;d", 1, -1, 1)
Str = Replace(Str, "truncate", "trunc&#097;te", 1, -1, 1)
Str = Replace(Str, "nchar", "nch&#097;r", 1, -1, 1)
Str = Replace(Str, "char", "ch&#097;r", 1, -1, 1)
Str = Replace(Str, "alter", "alt&#101;r", 1, -1, 1)
Str = Replace(Str, "cast", "ca&#115;t", 1, -1, 1)
Str = Replace(Str, "exists", "e&#120;ists", 1, -1, 1)
Str = Replace(Str,Chr(13),"<br>", 1, -1, 1)
CheckStr = Replace(Str,"'","''", 1, -1, 1)
End Function

2007-08-17 09:12
快速回复:请问: 这个代码限制了什么?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017280 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved