如果电子邮件总是封闭在最后<>
你可以
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