asp 判斷電子郵件郵箱的地址格式是否正確 我們可用下列辦法來(lái)解決這一問(wèn)題——但只是能夠判斷每個(gè)電子郵件地址的格式是否有效,并不能保證該地址確實(shí)存在。
第一種辦法:
% '**************************************************** '函數(shù)名:ChkMail '作 用:郵箱格式檢測(cè) '參 數(shù):Email ----Email地址 '返回值:True正確,F(xiàn)alse有誤 '**************************************************** Public Function ChkMail(ByVal Email) Dim Rep,Pmail : ChkMail = True : Set Rep = New RegExp Rep.Pattern = "([\.a-zA-Z0-9_-]){2,10}@([a-zA-Z0-9_-]){2,10}(\.([a-zA-Z0-9]){2,}){1,4}$" Pmail = Rep.Test(Email) : Set Rep = Nothing If Not Pmail Then ChkMail = False End Function %> 使用: If ChkMail("ls535427@2221262.com") = True Then Response.Write "格式正確" Else Response.Write "格式有誤" End If
Public Function IsEmail(ByVal PString) Dim Plt,Pgt : Plt = False : Pgt = False For x = 2 To Len(PString) - 1 If Mid(PString,x,1) = "@" Then Plt = True If Mid(PString,x,1) = "." And Plt = True Then Pgt = True Next If Plt = True And Pgt = True Then IsEmail = True Else IsEmail = False End if End Function %>
復(fù)制代碼 代碼如下:
% Function isemail(strng) isemail = false Dim regEx, Match Set regEx = New RegExp regEx.Pattern = "^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$" regEx.IgnoreCase = True Set Match = regEx.Execute(strng) if match.count then isemail= true End Function %>
js郵箱地址驗(yàn)證代碼
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁(yè)面才能執(zhí)行]
其實(shí)這里的很多代碼都是從一些知名的cms系統(tǒng)中,獲取的,就像一些比較不錯(cuò)的函數(shù),基本上為了節(jié)約時(shí)間可以多參考成熟系統(tǒng)的源碼中參考。 php 可以參考dedecms phpcms等 asp 可以參考 kesioncms 動(dòng)易等開(kāi)源的系統(tǒng) js 就可以多從一些網(wǎng)站下載js查看呵呵。