當前位置:開發者網絡 >> 技術教程 >> ASP教程 >> 客戶端相關 >> 內容
精彩推薦
分類最新教程
分類熱點教程
    
asp服務器端的驗證類
作者:未知
日期:2004-12-07
人氣:
投稿:snow(轉貼)
來源:未知
字體:
收藏:加入瀏覽器收藏
以下正文:
<%
'=================================================================
'Version:1.0
'Data=2004-7-5
'Script Written By: 幸福.net(Nicholas)
'==================================================================
'CopyRight By: 九州信息網絡有限公司
'web: www.21hb.com
'email:nicholas_cheung@21cn.com
'==================================================================
Class Cls_Validator
Rem =======================驗證類說明==============================
Rem=作用:對於輸入數據的驗證
Rem=例:set va=new Cls_Validator
Rem= va.Requirefield request("asd"),"錯誤請重新輸入"
Rem=
Rem=
Rem==================================================================
Private Validator1,Validator2
Public Property Get Validator() '定義屬性:驗證
Validator=Validator1
End Property
Public Property Let Validator(Validator2)
Validator1=Validator2
End Property
Public Function Requirefield(requestfieled,errorname)'確保用戶不跳輸的方法 errorname是輸入的字符串 requestname為錯誤信息
if requestfieled="" then
Requirefield=false
Validator1=false
Response.Write("<script lanuage='javascript'>alert('"&errorname&"');history.back()</script>")
Response.End()
else
Requirefield=true
Validator1=true
end if

End Function

Public Function CompareValidator(requestfieled1,requestfieled2,operator,errorname)'比較驗證的方法 requestfieled1,requestfieled2為輸入字符串 operator再比較符 errorname為錯誤信息
Select case operator '判斷比較運算符
Case ">"
if (not requestfieled1>requestfieled2) then
CompareValidator=false
Validator1=false
Response.Write("<script lanuage='javascript'>alert('"&errorname&"');history.back()</script>")
Response.End()
else
CompareValidator=True
Validator1=true
end if
Case "<"
if (not requestfieled1<requestfieled2) then
CompareValidator=false
Validator1=false
Response.Write("<script lanuage='javascript'>alert('"&errorname&"');history.back()</script>")
Response.End()
else
CompareValidator=True
Validator1=true
end if
Case "="
if (not requestfieled1=requestfieled2) then
CompareValidator=false
Validator1=false
Response.Write("<script lanuage='javascript'>alert('"&errorname&"');history.back()</script>")
Response.End()
else
CompareValidator=True
Validator1=true
end if
Case ">="
if (not requestfieled1>=requestfieled2) then
CompareValidator=false
Validator1=false
Response.Write("<script lanuage='javascript'>alert('"&errorname&"');history.back()</script>")
Response.End()
else
CompareValidator=True
Validator1=true
end if
Case "<="
if (not requestfieled1<=requestfieled2) then
CompareValidator=false
Validator1=false
Response.Write("<script lanuage='javascript'>alert('"&errorname&"');history.back()</script>")
Response.End()
else
CompareValidator=True
Validator1=true
end if
Case "<>"
if requestfieled1=requestfieled2 then
CompareValidator=false
Validator1=false
Response.Write("<script lanuage='javascript'>alert('"&errorname&"');history.back()</script>")
response.end()
else
CompareValidator=True
Validator1=true
end if
end Select
End Function

Public Function isnum(requestfieled,errorname)'判斷是否為數字。requestfieled為輸入字符串 errorname 為錯誤信息
if (not IsNumeric(requestfieled) )then
isnum=false
Validator1=false

Validator1=true
Response.Write("<script lanuage='javascript'>alert('"&errorname&"');history.back()</script>")
Response.End()
else
isnum=true
end if
End Function

Public Function legstr(requestfieled,num,errorname)'限制字符串的個數 requestfieled為輸入字符串 num為限制的字數 ,errorname為錯誤信息
numrequestfieled=cint(Len(requestfieled)) '獲取字符串的個數
if numrequestfieled>num then
legstr=false
Validator1=false
Response.Write("<script lanuage='javascript'>alert('"&errorname&"');history.back()</script>")
Response.End()
else
legstr=true
Validator1=true
end if
End Function

Public Function isemail(requestfieled,errorname)'判斷是否為電子郵箱格式 requestfieled為輸入值 errorname為錯誤信息
set re=new RegExp
re.Pattern=".*@.{2,}\..{2,}"
re.Global = True
re.IgnoreCase = True
re.MultiLine = True
if (not re.test(requestfieled)) then
isemail=false
Validator=false
Response.Write("<script lanuage='javascript'>alert('"&errorname&"');history.back()</script>")
Response.End()
else
isemail=true
end if
End Function
End Class
%>



相關文章: