ASP用正則驗證郵箱地址手機號碼電話號碼格式

來源:互聯網
上載者:User

經常需要驗證郵箱地址,手機號碼,電話號碼等。在這兒把ASP中的正則驗證實現記錄一下

Function validate(ByVal str,ByVal number)

Dim temp,reg

Set reg = new regexp

reg.ignorecase=true

reg.global=true

Select Case CStr(number)

' 英文+空格

Case "0" temp = "^[a-zA-Z ]+$"

' 數字+橫杠

Case "1" temp = "^[0-9\-]+$"

' 半形數字

Case "2" temp = "^\d+$"

' 郵箱地址

Case "3" temp = "^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"

' 手機號碼格式

Case "4" temp = "^(((13[0-9]{1})|159|153)+\d{8})$"

' 電話號碼格式1

Case "5" temp = "^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$"

' 電話號碼格式2

Case "6" temp = "^(([0\+]\d{2,3}-)?(0\d{2,3}))?(\d{7,8})(-(\d{3,}))?$"

Case Else temp = number

End Select

reg.pattern = temp

validate = reg.test(Trim(str))

Set reg = Nothing

End Function

條用方法:

if validate(tel,4) or validate(tel,5) or validate(tel,6) then

else

response.Write("<script language='javascript'>alert('請檢查您的聯絡電話或者手機號碼格式!'); history.back()</script>")

response.End()

end if

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.