asp ajax注册验证之 防止用户名输入空格
程序员文章站
2022-04-20 13:33:44
check.asp 复制代码 代码如下: <% '''''''''''''''''''''''''''''''''''' function replacetext(f...
check.asp
<%
''''''''''''''''''''''''''''''''''''
function replacetext(fstring,patrn,replstr)
set regex = new regexp ' 建立正则表达式。
regex.pattern = patrn ' 设置模式。
regex.ignorecase = true ' 设置是否区分大小写。
regex.global = true ' 设置全局可用性。
replacetext = regex.replace(""&fstring&"",""&replstr&"") ' 作替换。
set regex=nothing
end function
''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''
function htmlencode(fstring)
fstring=trim(fstring)
fstring=replace(fstring,chr(9),"")
fstring=replace(fstring,chr(13),"")
fstring=replace(fstring,chr(22),"")
fstring=replace(fstring,chr(38),"&") '“&”
fstring=replace(fstring,chr(32)," ") '“ ”
fstring=replace(fstring,chr(34),""") '“"”
fstring=replace(fstring,chr(37),"%") '“%”
fstring=replace(fstring,chr(39),"'") '“'”
fstring=replace(fstring,chr(42),"*") '“*”
fstring=replace(fstring,chr(43),"+") '“+”
fstring=replace(fstring,chr(44),",") '“,”
fstring=replace(fstring,chr(45)&chr(45),"--") '“--”
fstring=replace(fstring,chr(92),"\") '“\”
'fstring=replace(fstring,chr(95),"_") '“_”
fstring=replace(fstring,chr(40),"(") '“(”
fstring=replace(fstring,chr(41),")") '“)”
fstring=replace(fstring,chr(60),"<") '“<”
fstring=replace(fstring,chr(62),">") '“>”
fstring=replace(fstring,chr(123),"{") '“{”
fstring=replace(fstring,chr(125),"}") '“}”
fstring=replace(fstring,chr(59),";") '“;”
fstring=replace(fstring,chr(10),"<br>")
fstring=replacetext(fstring,"([])([a-z0-9]*);","$1$2;")
fstring=replacetext(fstring,"(fuck|shit)",string(len("&$1&"),"*"))
if issqldatabase=0 then '过滤片假名(日文字符)[\u30a0-\u30ff] by yuzi
fstring=escape(fstring)
fstring=replacetext(fstring,"%u30([a-f][0-f])","0$1;")
fstring=unescape(fstring)
end if
htmlencode=fstring
end function
''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''
function requestint(fstring)
requestint=request(fstring)
if isnumeric(requestint) then
requestint=int(requestint)
else
requestint=0
end if
end function
''''''''''''''''''''''''''''''''''''
username=htmlencode(unescape(request.querystring("username")))
usernamelength=requestint("usernamelength")
if len(username)<>usernamelength then
response.write "用户名非法!"
else
response.write "用户名合法!"
end if
%>
htmlencode 函数是将用户名转换成合法字符的必须步骤。
requestint 函数主要根据输入有效字符的个数判断用户名是否包含空格。
调用方法:check.asp?username=用户名&usernamelength=用户名长度
check.asp一般用于ajax判断
复制代码 代码如下:
<%
''''''''''''''''''''''''''''''''''''
function replacetext(fstring,patrn,replstr)
set regex = new regexp ' 建立正则表达式。
regex.pattern = patrn ' 设置模式。
regex.ignorecase = true ' 设置是否区分大小写。
regex.global = true ' 设置全局可用性。
replacetext = regex.replace(""&fstring&"",""&replstr&"") ' 作替换。
set regex=nothing
end function
''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''
function htmlencode(fstring)
fstring=trim(fstring)
fstring=replace(fstring,chr(9),"")
fstring=replace(fstring,chr(13),"")
fstring=replace(fstring,chr(22),"")
fstring=replace(fstring,chr(38),"&") '“&”
fstring=replace(fstring,chr(32)," ") '“ ”
fstring=replace(fstring,chr(34),""") '“"”
fstring=replace(fstring,chr(37),"%") '“%”
fstring=replace(fstring,chr(39),"'") '“'”
fstring=replace(fstring,chr(42),"*") '“*”
fstring=replace(fstring,chr(43),"+") '“+”
fstring=replace(fstring,chr(44),",") '“,”
fstring=replace(fstring,chr(45)&chr(45),"--") '“--”
fstring=replace(fstring,chr(92),"\") '“\”
'fstring=replace(fstring,chr(95),"_") '“_”
fstring=replace(fstring,chr(40),"(") '“(”
fstring=replace(fstring,chr(41),")") '“)”
fstring=replace(fstring,chr(60),"<") '“<”
fstring=replace(fstring,chr(62),">") '“>”
fstring=replace(fstring,chr(123),"{") '“{”
fstring=replace(fstring,chr(125),"}") '“}”
fstring=replace(fstring,chr(59),";") '“;”
fstring=replace(fstring,chr(10),"<br>")
fstring=replacetext(fstring,"([])([a-z0-9]*);","$1$2;")
fstring=replacetext(fstring,"(fuck|shit)",string(len("&$1&"),"*"))
if issqldatabase=0 then '过滤片假名(日文字符)[\u30a0-\u30ff] by yuzi
fstring=escape(fstring)
fstring=replacetext(fstring,"%u30([a-f][0-f])","0$1;")
fstring=unescape(fstring)
end if
htmlencode=fstring
end function
''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''
function requestint(fstring)
requestint=request(fstring)
if isnumeric(requestint) then
requestint=int(requestint)
else
requestint=0
end if
end function
''''''''''''''''''''''''''''''''''''
username=htmlencode(unescape(request.querystring("username")))
usernamelength=requestint("usernamelength")
if len(username)<>usernamelength then
response.write "用户名非法!"
else
response.write "用户名合法!"
end if
%>
htmlencode 函数是将用户名转换成合法字符的必须步骤。
requestint 函数主要根据输入有效字符的个数判断用户名是否包含空格。
调用方法:check.asp?username=用户名&usernamelength=用户名长度
check.asp一般用于ajax判断
上一篇: 爆笑的同学们,好嗨哟!