#######################
#作者:雨浪 版權(quán)所有,翻版說(shuō)一下 ?。?
#QQ:270499458 ?。?
#######################
近段日子幾個(gè)剛學(xué)了正則表達(dá)式的朋友問(wèn)我在asp中怎么用.呵呵.雖然簡(jiǎn)單,還是寫(xiě)出來(lái)吧,正則表達(dá)式的基本知識(shí)我就不說(shuō)了.其實(shí)已經(jīng)有很多這樣的文章了.:(
#####函數(shù)代碼########
假設(shè)為myfunc.asp
%
'正則表表達(dá)式驗(yàn)證函數(shù) patrn-正則表達(dá)式 strng-需要驗(yàn)證的字符串
Function RegExpTest(patrn, strng)
Dim regEx, retVal ' 建立變量。
Set regEx = New RegExp ' 建立正則表達(dá)式。
regEx.Pattern = patrn ' 設(shè)置模式。
regEx.IgnoreCase = False ' 設(shè)置是否區(qū)分大小寫(xiě)。
retVal = regEx.Test(strng) ' 執(zhí)行搜索測(cè)試。
RegExpTest = retVal '返回不爾值,不符合就返回false,符合為true
End Function
%>
#####提交頁(yè)面代碼######
假設(shè)為mypage.asp
form method="post" action="check.asp">
請(qǐng)輸入E-mail地址:input type=text name=email>
br>
請(qǐng)輸入電話號(hào)碼:input type=text name=tel>
input type=submit value="確定">
/form>
#####驗(yàn)證頁(yè)面########
假設(shè)為check.asp
!--#include file="myfunc.asp"-->
%
tel=request.form("tel")
email=request.form("email")
dim founderr : founderr=false '建立變量,正確或者失敗標(biāo)記
'大家注意哦,順便我在這里貢獻(xiàn)一個(gè)正則表達(dá)式,同時(shí)驗(yàn)證電話號(hào)碼和手機(jī)號(hào)碼的!
if RegExpTest("(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)", tel)=false then
founderr=true
regshow=regshow"li>您輸入的電話號(hào)碼格式不正確"
end if
if RegExpTest("^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$", email)=false then
founderr=true
regshow=regshow"li>您輸入的電子郵箱格式不正確"
end if
if founderr=false then regshow="li>您輸入的格式都是正確的哦"
%>
br>br>
%=regshow%>