www.gusucode.com > CC校友录贴吧 CCBar源码程序asp编程 > class/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 %>