<%
Function IsValidUserName(UserName)
IsValidUserName = True
'判斷使用者名稱長度是否在3-20字元之間
If Len(UserName)<3 or Len(UserName)>20 Then
IsValidUserName=False
Exit Function
End If
'檢測是否包含特殊字元,可能造成不安全的SQL注入
For i = 1 To Len(UserName)
c = Lcase(Mid(UserName, i, 1))
If InStr("$!<>?#^%@~`&*();:+='"" ", c) > 0 Then
IsValidUserName = False
Exit Function
End IF
Next
'判斷輸入的使用者名稱是否是中文字元,英文字元(大小寫),數字,底線,中文字元組合
Dim regEx, Match1, Matches ' 建立變數。
Set regEx = New RegExp ' 建立Regex。
regEx.Pattern ="[^0-9a-z_/u4e00-/u9fa5]" ' 設定模式。
regEx.IgnoreCase = True ' 設定是否區分字元大小寫。
regEx.Global = True ' 設定全域可用性。
Set Matches = regEx.Execute(UserName) ' 執行搜尋。
For Each Match1 in Matches ' 遍曆匹配集合。
RetStr = RetStr & "找到非法字元位置:" & Match1.FirstIndex & " 字元是:"& Match1.Value & "" & vbCRLF
Next
response.Write("<br>"&RetStr)
if RetStr="" then
IsValidUserName = True
else
IsValidUserName = False
end if
RegExpTest = RetStr
End Function
response.Write(IsValidUserName("我是_xqf222"))
response.Write(IsValidUserName("我是_xqf 222"))
%>