asp 驗證(zhèng)輸入網址(zhǐ)是否有效並可以訪問 與正則驗(yàn)證輸入
<%
'******************************
'函數:UrlOK(strURL)
'參數:strURL,待驗(yàn)證(zhèng)的網址
'作者(zhě):阿裏西西
'日期:2007/7/13
'描述:驗證輸入網址是否有(yǒu)效並可以訪問
'示例:<%=UrlOK("http://www.ynaad.com")%>
'******************************
Function UrlOK(strURL)
On Error Resume Next
If strURL<>"" Then
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
objHTTP.Open "GET", strURL, FALSE
objHTTP.Send
If instr(objHTTP.statusText,"OK") Then
UrlOK = "有效"
Else
UrlOK = "無(wú)效"
End if
Else
UrlOK = "錯誤(wù):您沒有輸入網址!"
End If
End Function
%>
<%=UrlOK("http://www.ynaad.com")%>
測試通過!
正則驗證輸入網址是否合法的(de)URL
<%
'******************************
'函數:checkexp(patrn,strng)
'參數:patrn 正則表達式;strng 驗證字(zì)符串
'作者:阿(ā)裏西西
'日期:2007/7/13
'描述:正則驗證輸入網址是否合法的(de)URL
'示例:<%=checkexp(patrn,strng)%>
'******************************
function checkexp(patrn,strng)
dim regex,match
set regex = new regexp ' 建立正則表達式。
regex.pattern = patrn ' 設置模(mó)式。
regex.ignorecase = true ' 設置是否區分字符大小寫。
regex.global = true ' 設置全局可用性。
matches = regex.test(strng)
checkexp = matches
end function
%>
關鍵(jiàn)詞:asp
閱讀本(běn)文後您有什麽感想? 已有 人(rén)給出評價!
- 0
- 0
- 0
- 0
- 0
- 0