美国石油进口2016比重:ASP脚本的含义

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 22:26:36
if ((contain(document.Send.NAME.value, "%\(\)><")) || (contain(document.Send.MESSAGE.value, "%\(\)><")))
{
alert("信息!");
document.Send.NAME.focus();
return false;
}
return true;
}

使用这个脚本当出现什麽问题是会被阻止?

是否是包含"%\(\)><"))这些符号?
那我该如何使得他不那麽敏感,因为很多人说无法留言,是否是他们的名字包含非法字符?怎麽改好?

这个是正则表达式验证,关于正则表达式你可以参考以下文章:

http://www.pconline.com.cn/pcedu/empolder/wz/php/0509/695748.html

或者百度一下。

这个正则表达式验证内容是:只有当用户名NAME和留言信息MESSAGE都不包含(、)、<、>、%这些符号时才予以发表。

一般情况下,不建议在javascript里对输入信息做验证,因为这很容易破解。我推荐你在处理表单的asp里做验证,最好自己写一个函数。我写的函数如下:

<%
'------------------------
'Project By BTwork Studio
'Code:[BT]Ok
'Date:2004-9-23
'------------------------
Function Check_Str(Input)

Output = False
If InStr(Input,Chr(32)) Then Output = True '空格
If InStr(Input,Chr(33)) Then Output = True '!
If InStr(Input,Chr(34)) Then Output = True '"
If InStr(Input,Chr(35)) Then Output = True '#
If InStr(Input,Chr(36)) Then Output = True '$
If InStr(Input,Chr(37)) Then Output = True '%
If InStr(Input,Chr(38)) Then Output = True '&
If InStr(Input,Chr(39)) Then Output = True ''
If InStr(Input,Chr(42)) Then Output = True '*
If InStr(Input,Chr(43)) Then Output = True '+
If InStr(Input,Chr(44)) Then Output = True ',
If InStr(Input,Chr(46)) Then Output = True '.
If InStr(Input,Chr(47)) Then Output = True '/
If InStr(Input,Chr(58)) Then Output = True ':
If InStr(Input,Chr(59)) Then Output = True ':
If InStr(Input,Chr(60)) Then Output = True '<
If InStr(Input,Chr(61)) Then Output = True '=
If InStr(Input,Chr(62)) Then Output = True '>
If InStr(Input,Chr(63)) Then Output = True '?
If InStr(Input,Chr(64)) Then Output = True '@
If InStr(Input,Chr(91)) Then Output = True '[
If InStr(Input,Chr(92)) Then Output = True '\
If InStr(Input,Chr(93)) Then Output = True ']
If InStr(Input,Chr(94)) Then Output = True '^
If InStr(Input,Chr(96)) Then Output = True '`
If InStr(Input,Chr(123)) Then Output = True '{
If InStr(Input,Chr(124)) Then Output = True '|
If InStr(Input,Chr(125)) Then Output = True '}
If InStr(Input,Chr(126)) Then Output = True '~
Check_Str = Output

End Function

%>

以上语句可以自行调整,这个是用作对用户名等关键信息进行强验证,不支持.,*-!@#%()~等常用符号,下面是对用户其他信息进行的弱验证,支持绝大多数符号:

<%
Function Check_Str_(Input)

Output = False
If InStr(Input,Chr(34)) Then Output = True '"
If InStr(Input,Chr(36)) Then Output = True '$
If InStr(Input,Chr(38)) Then Output = True '&
If InStr(Input,Chr(39)) Then Output = True ''
If InStr(Input,Chr(42)) Then Output = True '*
If InStr(Input,Chr(43)) Then Output = True '+
If InStr(Input,Chr(47)) Then Output = True '/
If InStr(Input,Chr(58)) Then Output = True ':
If InStr(Input,Chr(59)) Then Output = True ';
If InStr(Input,Chr(60)) Then Output = True '<
If InStr(Input,Chr(61)) Then Output = True '=
If InStr(Input,Chr(62)) Then Output = True '>
If InStr(Input,Chr(91)) Then Output = True '[
If InStr(Input,Chr(92)) Then Output = True '\
If InStr(Input,Chr(93)) Then Output = True ']
If InStr(Input,Chr(94)) Then Output = True '^
If InStr(Input,Chr(96)) Then Output = True '`
If InStr(Input,Chr(123)) Then Output = True '{
Check_Str_ = Output

End Function

%>

希望对你有帮助:)

首先说明,此不是asp脚本,而是javascript
(假定contain函数已经定义,验证字符串)
脚本首先验证表单域NAME和MESSAGE中是否输入非法字符“%\(\)><”,如果其中包含任何定义的非法字符,将弹出提示框,并使NAME为激活状态,返回假;否则返回真。

附:
function contain(str,charset)// 字符串包含测试函数

{

var i;

for(i=0;i<charset.length;i++)

if(str.indexOf(charset.charAt(i))>=0)

return true;

return false;

}

晕了,如果你区分不开他是什么角本的话,那你就先不要管他是什么意思,先系统的学习一下VBscript或JAVAscript

说得对,就是那个意思哈
它是js脚本,而不是asp脚本!!!