?? class_client_check.asp
字號:
<%
'===================================================================
'= ASP FILENAME : /class/class_client_check.asp
'= CREATED TIME : 2005-8-6 7:26
'= LAST MODIFIED: 2005-8-6 7:26
'= VERSION INFO : CCASP Framework Ver 2.0.1 ALL RIGHTS RESERVED BY www.cclinux.com
'= DESCRIPTION : 客戶端腳本校驗自動生成
'= Usage:
'== 是否進行客戶端數據校驗
'= Dim GBL_blnClientDataCheck = True
'= ReDim arrDataChk(1)
'= 固定長度
'= arrDataChk(0) = Array("DT_FIX_LENGTH" , "iptName" , "下載資源名稱",1,4)
'= 正整數
'= arrDataChk(1) = Array("DT_PLUS_INT" , "iptDes" , "下載資源描述")
'= 文本
'= DT_CONTENT
'= Change Log :
'= 2006-7-20 增加字母數字下劃線校驗CheckAsc
'===================================================================
Class classClientChk
Private strOutJsCode
Public strForm
'===================================================================
'= Description : Class's initialization
'= Time : Created At 2005-8-6 7:28
'= Modify :
'===================================================================
Private Sub Class_Initialize()
End Sub
'===================================================================
'= Description : Class's terminate
'= Time : Created At 2005-8-6 7:30
'= Modify :
'===================================================================
Private Sub Class_Terminate()
End Sub
'== 長度校驗
Private Function CheckLength(strName,strShow,intMin,intMax)
Dim strJsCode
strJsCode = ""
If intMin = intMax Then
strJsCode = "if (" & strForm & "." & strName & ".value.length != " & intMin & " ) " & chr(13) & chr(10)
strJsCode = strJsCode & "{" & chr(13) & chr(10)
strJsCode = strJsCode & " alert('" & strShow & "的長度必須為" & intMin & "位');" & chr(13) & chr(10)
strJsCode = strJsCode & " if (" & strForm & "." & strName & ".type != 'hidden')" & chr(13) & chr(10)
strJsCode = strJsCode & " " & strForm & "." & strName & ".focus();" & chr(13) & chr(10)
strJsCode = strJsCode & " return false;" & chr(13) & chr(10)
strJsCode = strJsCode & "}" & chr(13) & chr(10)
Else
strJsCode = "if (" & strForm & "." & strName & ".value.length < " & intMin & " || " & strForm & "." & strName & ".value.length > " & intMax & " ) " & chr(13) & chr(10)
strJsCode = strJsCode & "{" & chr(13) & chr(10)
strJsCode = strJsCode & " alert('" & strShow & "的長度必須為" & intMin & "--" & intMax & "位');" & chr(13) & chr(10)
strJsCode = strJsCode & " if (" & strForm & "." & strName & ".type != 'hidden')" & chr(13) & chr(10)
strJsCode = strJsCode & " " & strForm & "." & strName & ".focus();" & chr(13) & chr(10)
strJsCode = strJsCode & " return false;" & chr(13) & chr(10)
strJsCode = strJsCode & "}" & chr(13) & chr(10)
End If
CheckLength = strJsCode
End Function
'== 正整數
Function CheckPlusNumber(strName,strShow)
Dim strJsCode
strJsCode = ""
strJsCode = strJsCode & CheckReg(REG_PLUS_NUMBER,strName,strShow,true)
strJsCode = strJsCode & "if (" & strForm & "." & strName & ".value < 0 || " & strForm & "." & strName & ".value > " & adMaxIntValue & ")" & chr(13) & chr(10)
strJsCode = strJsCode & "{" & chr(13) & chr(10)
strJsCode = strJsCode & " alert('" & strShow & "的取值范圍應該為0 -- " & adMaxIntValue & "');" & chr(13) & chr(10)
strJsCode = strJsCode & " if (" & strForm & "." & strName & ".type != 'hidden')" & chr(13) & chr(10)
strJsCode = strJsCode & " " & strForm & "." & strName & ".focus();" & chr(13) & chr(10)
strJsCode = strJsCode & " return false;" & chr(13) & chr(10)
strJsCode = strJsCode & "}" & chr(13) & chr(10)
strJsCode = strJsCode & chr(13) & chr(10)
CheckPlusNumber = strJsCode
End Function
'== 非法字符
Function CheckValidity(strName,strShow)
Dim strJsCode
strJsCode = ""
strJsCode = strJsCode & CheckReg(adValidity,strName,strShow,true)
CheckValidity = strJsCode
End Function
'== 正則表達式校驗
Function CheckReg(strType,strName,strShow,bolFlag)
Dim strJsCode : strJsCode = ""
strJsCode = " var check = /" & strType & "/;" & chr(13) & chr(10)
If bolFlag = true Then
strJsCode = strJsCode & " if (!check.test(" & strForm & "." & strName & ".value))" & chr(13) & chr(10)
Else
strJsCode = strJsCode & " if (check.test(" & strForm & "." & strName & ".value))" & chr(13) & chr(10)
End If
strJsCode = strJsCode & "{" & chr(13) & chr(10)
strJsCode = strJsCode & " alert('" & strShow & "輸入有誤');" & chr(13) & chr(10)
'== 處理隱藏表單
strJsCode = strJsCode & " if (" & strForm & "." & strName & ".type != 'hidden')" & chr(13) & chr(10)
strJsCode = strJsCode & " " & strForm & "." & strName & ".focus();" & chr(13) & chr(10)
strJsCode = strJsCode & " return false;" & chr(13) & chr(10)
strJsCode = strJsCode & "}" & chr(13) & chr(10)
CheckReg = strJsCode
End Function
'== 枚舉校驗
Function CheckEnum(strName,strShow,strEnum)
Dim strJsCode : strJsCode = ""
strEnum = "," & strEnum & ","
strJsCode = "var " & strName & "Str = '" & strEnum & "';" & chr(13) & chr(10)
strJsCode = strJsCode & "var " & strName & "Num = " & strName & "Str.indexOf(','+" & strForm & "." & strName & ".value+',');" & chr(13) & chr(10)
strJsCode = strJsCode & " if (" & strName & "Num < 0) " & chr(13) & chr(10)
strJsCode = strJsCode & "{" & chr(13) & chr(10)
strJsCode = strJsCode & " alert('" & strShow & "輸入不在可接受的范圍');" & chr(13) & chr(10)
strJsCode = strJsCode & " if (" & strForm & "." & strName & ".type != 'hidden')" & chr(13) & chr(10)
strJsCode = strJsCode & " " & strForm & "." & strName & ".focus();" & chr(13) & chr(10)
strJsCode = strJsCode & " return false;" & chr(13) & chr(10)
strJsCode = strJsCode & "}" & chr(13) & chr(10)
CheckEnum = strJsCode
End Function
'== 正數取值范圍校驗
Function ChkIntBetween(strName,strShow,intMin,intMax)
Dim strJsCode
strJsCode = ""
'== 校驗是否為數字
strJsCode = CheckReg(REG_NUMBER,strName,strShow,true)
If intMin = intMax Then
strJsCode = strJsCode & "if (" & strForm & "." & strName & ".value != " & intMin & " ) " & chr(13) & chr(10)
strJsCode = strJsCode & "{" & chr(13) & chr(10)
strJsCode = strJsCode & " alert('" & strShow & "的取值必須為" & intMin & "');" & chr(13) & chr(10)
strJsCode = strJsCode & " if (" & strForm & "." & strName & ".type != 'hidden')" & chr(13) & chr(10)
strJsCode = strJsCode & " " & strForm & "." & strName & ".focus();" & chr(13) & chr(10)
strJsCode = strJsCode & " return false;" & chr(13) & chr(10)
strJsCode = strJsCode & "}" & chr(13) & chr(10)
Else
strJsCode = strJsCode & "if (" & strForm & "." & strName & ".value < " & intMin & " || " & strForm & "." & strName & ".value > " & intMax & " ) " & chr(13) & chr(10)
strJsCode = strJsCode & "{" & chr(13) & chr(10)
strJsCode = strJsCode & " alert('" & strShow & "的取值范圍必須為" & intMin & "--" & intMax & "');" & chr(13) & chr(10)
strJsCode = strJsCode & " if (" & strForm & "." & strName & ".type != 'hidden')" & chr(13) & chr(10)
strJsCode = strJsCode & " " & strForm & "." & strName & ".focus();" & chr(13) & chr(10)
strJsCode = strJsCode & " return false;" & chr(13) & chr(10)
strJsCode = strJsCode & "}" & chr(13) & chr(10)
End If
ChkIntBetween = strJsCode
End Function
'== ID參數校驗
Function CheckId(strName,strShow)
CheckId = CheckReg(REG_PLUS_NUMBER,strName,strShow & "ID參數",True)
End Function
'== Email校驗
Function CheckEmail(strName,strShow)
CheckEmail = CheckReg(REG_EMAIL,strName,strShow ,True)
End Function
'== Url校驗
Function CheckUrl(strName,strShow)
CheckUrl = CheckReg(REG_URL,strName,strShow ,True)
End Function
'== 字母/數據/下劃線校驗
Function CheckAsc(strName,strShow)
Dim strJsCode
strJsCode = ""
strJsCode = strJsCode & "var check = /" & REG_ASC & "/;" & chr(13) & chr(10)
strJsCode = strJsCode & "if (!check.test(" & strForm & "." & strName & ".value))" & chr(13) & chr(10)
strJsCode = strJsCode & "{" & chr(13) & chr(10)
strJsCode = strJsCode & " alert(""" & strShow & """ + ""必須為英文,數字和下劃線"");" & chr(13) & chr(10)
strJsCode = strJsCode & " " & strForm & "." & strName & ".focus();" & chr(13) & chr(10)
strJsCode = strJsCode & " return false;" & chr(13) & chr(10)
strJsCode = strJsCode & "}" & chr(13) & chr(10)
CheckAsc = strJsCode
End Function
'== 客戶端數據校驗主函數
Public Function ClientDataCheck(strTheForm,arrDataChk)
Dim strOutJs
Dim i
'== 是否進行客戶端數據校驗
If GBL_blnClientDataCheck = False Then
ClientDataCheck = ""
Exit Function
End If
strForm = strTheForm
strOutJs = ""
For i = LBound(arrDataChk) To UBound(arrDataChk)
'== 非法字符校驗
'strOutJs = strOutJs & CheckValidity(arrDataChk(i)(1),arrDataChk(i)(2))
strOutJs = strOutJs & chr(13) & chr(10)
Select Case arrDataChk(i)(0)
Case "DT_FIX_LENGTH" :
strOutJs = strOutJs & CheckLength(arrDataChk(i)(1),arrDataChk(i)(2),arrDataChk(i)(3),arrDataChk(i)(4))
Case "DT_CONTENT" :
Case "DT_INT_BETWEEN":
strOutJs = strOutJs & ChkIntBetween(arrDataChk(i)(1),arrDataChk(i)(2),arrDataChk(i)(3),arrDataChk(i)(4))
Case "DT_PLUS_INT":
strOutJs = strOutJs & CheckPlusNumber(arrDataChk(i)(1),arrDataChk(i)(2))
Case "DT_EMAIL":
strOutJs = strOutJs & CheckEmail(arrDataChk(i)(1),arrDataChk(i)(2))
Case "DT_URL":
strOutJs = strOutJs & CheckUrl(arrDataChk(i)(1),arrDataChk(i)(2))
Case "DT_ENUM":
strOutJs = strOutJs & CheckEnum(arrDataChk(i)(1),arrDataChk(i)(2),arrDataChk(i)(3))
Case "DT_ID" :
strOutJs = strOutJs & CheckId(arrDataChk(i)(1),arrDataChk(i)(2))
Case "DT_ASC" :
strOutJs = strOutJs & CheckAsc(arrDataChk(i)(1),arrDataChk(i)(2))
Case Else strOutJs = strOutJs
End Select
Next
ClientDataCheck = strOutJs
End Function
End Class
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -