如果電子郵件總是封閉在最後<>
你可以
Public Function fmt(email As String) As String
pos = InStrRev(email, "<")
If (pos > 0) Then
email = Mid$(email, 1 + pos, 1 + Len(email) - pos)
email = Left$(email, Len(email) - 1)
End If
fmt = email
End Function
或
replace(mid(email,instrrev(email,"<")+1,len(email)),">","")
編輯;
對於正則表達式檢查,添加對「Microsoft VBScript正則表達式庫」(工具>引用)的引用;
Public Function fmt(email As String) As String
pos = InStrRev(email, "<")
If (pos > 0) Then
email = Mid$(email, 1 + pos, 1 + Len(email) - pos)
email = Left$(email, Len(email) - 1)
End If
fmt = email
With New RegExp
.Global = True
.IgnoreCase = True
.MultiLine = True
.Pattern = "^\[email protected]\S+\.\S+$"
If Not .Test(fmt) Then fmt = ""
End With
End Function
這將返回一個有效的電子郵件地址,或者「」如果它無效。
我放棄了你的RE;推理:Using a regular expression to validate an email address
後期綁定優於創建引用。 – 2011-04-29 02:37:02
@David:嗯,這取決於:對於開發,早期綁定可以幫助很多人(智能感知等),特別是對那些沒有經驗的開發人員來說,他們並不太瞭解庫的對象模型。當然,爲了部署,切換到後期綁定可以節省很多麻煩。 – Heinzi 2011-04-29 05:34:23
我致力於爲客戶提供簡單可靠的服務。有時這意味着我作爲開發人員必須更加努力地工作。 – 2011-04-30 19:01:57