Input Validation Class Validator

Source: Internet
Author: User
Tags chr eval min range servervariables trim

<% @Language = "VBScript" codepage= "936"%>
<%
' Option Explicit
Class Validator
''*************************************************
' Validator for ASP Beta 3 server-side script
"Code by my Foshan people
"' Wfsr@cunite.com
''*************************************************
Private Re
Private Icodename
Private Icodesessionname

Public Property Let codename (ByVal Pcodename)
Icodename = Pcodename
End Property

Public Property Get codename ()
codename = Icodename
End Property

Public Property Let Codesessionname (ByVal pcodesessionname)
Icodesessionname = Pcodesessionname
End Property

Public Property Get Codesessionname ()
Codesessionname = Icodesessionname
End Property

Private Sub Class_Initialize ()
Set Re = New RegExp
Re.ignorecase = True
Re.global = True
Me.codename = "Vcode"
Me.codesessionname = "Vcode"
End Sub

Private Sub Class_Terminate ()
Set Re = Nothing
End Sub

Public Function Isemail (ByVal Str)
Isemail = Test ("^\w+" ([-+.) \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$ ", STR)
End Function

Public Function Isurl (ByVal Str)
Isurl = Test ("^http:\/\/[a-za-z0-9]+\.[ a-za-z0-9]+[\/=\?%\ -&_~ ' @[\]\ ': +!] * ([^<> ""]) *$ ", STR)
End Function

Public Function Isnum (ByVal Str)
isnum= Test ("^\d+$", STR)
End Function

Public Function isqq (ByVal Str)
ISQQ = Test ("^[1-9]\d{4,8}$", STR)
End Function

Public Function Iszip (ByVal Str)
Iszip = Test ("^[1-9]\d{5}$", STR)
End Function

Public Function Isidcard (ByVal Str)
Isidcard = Test ("^\d{15}" (\d{2}[a-za-z0-9))? $ ", STR)
End Function

Public Function Ischinese (ByVal Str)
Ischinese = Test ("^[\u0391-\uffe5]+$", STR)
End Function

Public Function isenglish (ByVal Str)
Isenglish = Test ("^[a-za-z]+$", STR)
End Function

Public Function IsMobile (ByVal Str)
IsMobile = Test ("^" (\d{3}\) | ( \d{3}\-))? 13\d{9}$ ", STR)
End Function

Public Function Isphone (ByVal Str)
Isphone = Test ("^" (\d{3}\) | ( \d{3}\-))? (\ (0\d{2,3}\) |0\d{2,3}-)? [1-9]\d{6,7}$, Str]
End Function

Public Function Issafe (ByVal Str)
Issafe = (Test ("^" ([a-z]*|[ a-z]*|\d*| [-_\~!@#\$%\^&\*\.\ (\) \[\]\{\}<>\?\\\/\ ' ""]*) |. {0,5}) $|\s ", Str) = False)
End Function

Public Function Isnotempty (ByVal Str)
Isnotempty = LenB (STR) > 0
End Function

Public Function Isdateformat (ByVal Str, ByVal Format)
IF not IsDate (STR) Then
Isdateformat = False
Exit Function
End IF

IF Format = "YMD" Then
Isdateformat = Test ("^" (\d{4}) | ( \D{2})) ([-./]) (\d{1,2}) \4 (\d{1,2}) $ ", Str)
Else
Isdateformat = Test ("^ (\d{1,2}) ([-./]) (\d{1,2}) \\2 ((\d{4}) | ( \D{2})) $ ", Str"
End IF
End Function

Public Function isequal (ByVal Src, ByVal Tar)
IsEqual = (SRC = Tar)
End Function

Public Function Compare (ByVal Op1, ByVal Operator, ByVal Op2)
Compare = False
IF dic.exists (Operator) Then
Compare = Eval (Dic.item (Operator))
Elseif isnotempty (OP1) Then
Compare = Eval (Op1 & Operator & OP2)
End IF
End Function

Public Function Range (ByVal Src, ByVal Min, ByVal Max)
min = CInt (min): max = CInt (max)
Range = (Min < src and src < Max)
End Function

Public Function Group (ByVal Src, ByVal Min, ByVal Max)
min = CInt (min): max = CInt (max)
Dim num:num = UBound (Split (SRC, ",")) + 1
Group = Range (Num, Min-1, Max + 1)
End Function

Public Function Custom (ByVal Str, ByVal Reg)
Custom = Test (Reg, STR)
End Function

Public Function Limit (ByVal Str, ByVal Min, ByVal Max)
min = CInt (min): max = CInt (max)
Dim l:l = Len (STR)
Limit = (Min <= l and L <= Max)
End Function

Public Function LIMITB (ByVal Str, ByVal Min, ByVal Max)
min = CInt (min): max = CInt (max)
Dim l:l =blen (STR)
LIMITB = (Min <= l and L <= Max)
End Function

Private Function Test (ByVal pattern, ByVal Str)
If IsNull (str) Or isempty (str) Then
Test = False
Else
Re.pattern = Pattern
Test = Re.test (CStr (STR))
End If
End Function

Public Function Blen (ByVal Str)
Blen = Len (Replace (STR, [^\x00-\xff], "..."))
End Function

Private Function Replace (ByVal Str, ByVal pattern, ByVal restr)
Re.pattern = Pattern
Replace = Re.replace (Str, RESTR)
End Function

Private Function b2s (ByVal istr)
Dim reval:reval= ""
Dim I, Code, ncode
For i = 1 to LenB (ISTR)
Code = AscB (MidB (ISTR, I, 1))
IF Code < &h80 Then
ReVal = ReVal & Chr (Code)
Else
Ncode = AscB (MidB (ISTR, i+1, 1))
ReVal = ReVal & Chr (CLng (Code) * &h100 + CInt (ncode))
i = i + 1
End IF
Next
B2s = ReVal
End Function

Public Function safestr (ByVal Name)
If IsNull (name) Or IsEmpty (name) Then
Safestr = False
Else
Safestr = Replace (Trim (Name), "(\s*and\s*\w*=\w*) |[" %&<>=] "," "")
End If
End Function

Public Function Safeno (ByVal Name)
If IsNull (name) Or IsEmpty (name) Then
Safeno = 0
Else
Safeno = (Replace (Trim (Name), "^[\d]* (\d+) [\d\d]*$", "$")
End If
End Function

Public Function Isvalidcode ()
Isvalidcode = (Request.Form (me.codename) = Session (Me.codesessionname)) and session (Me.codesessionname) <> "")
End Function

Public Function Isvalidpost ()
Dim URL1:URL1 = Cstr (Request.ServerVariables ("Http_referer"))
Dim url2:url2 = Cstr (Request.ServerVariables ("SERVER_NAME"))
Isvalidpost = (Mid (URL1, 8, Len (URL2)) = Url2)
End Function

End Class
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.