asp服务器端的验证类

类别:Asp 点击:0 评论:0 推荐:

<%
'=================================================================
'Version:1.0
'Data=2004-7-5
'Script Written By: 幸福.net(Nicholas)
'==================================================================
'CopyRight By: 九州信息网络有限公司
'web: www.21hb.com
'email:[email protected]
'==================================================================
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
%>

本文地址:http://com.8s8s.com/it/it7853.htm