我有一个列,人们手动输入电子邮件地址.我想使用以下公式验证电子邮件地址:
=AND(FIND(“@”,A2),FIND(“.”,A2),ISERROR(FIND(” “,A2)))
Run Code Online (Sandbox Code Playgroud)
但excel会出现错误,即您键入的公式包含错误.对我来说,公式看起来是对的.你们有什么建议吗?
Pet*_* L. 20
我的代码出现了同样的错误,看起来你没有"普通"双引号,这与这个符号不同:".
试试我的拼写:=AND(FIND("@",A2),FIND(".",A2),ISERROR(FIND(" ",A2)))- 希望会有所帮助!
编辑:
另外,考虑使用=AND(NOT(ISERROR(FIND("@",A1))),NOT(ISERROR(FIND(".",A1))),ISERROR(FIND(" ",A1)))- 这将防止错误@或.丢失.尽管如此,这仍然可以通过aaa@.,但我认为即使是这种直截了当的方法也有权使用)
Joe*_*oel 11
在excel中验证电子邮件的另一种方法是使用VBA代码:请参阅以下代码,该代码取自http://www.vbaexpress.com/kb/getarticle.php?kb_id=281,它的工作原理非常好,您可以修改基于代码的代码根据您的需求.
Sub email()
Dim txtEmail As String
txtEmail = InputBox("Type the address", "e-mail address")
Dim Situacao As String
' Check e-mail syntax
If IsEmailValid(txtEmail) Then
Situacao = "Valid e-mail syntax!"
Else
Situacao = "Invalid e-mail syntax!"
End If
' Shows the result
MsgBox Situacao
End Sub
Function IsEmailValid(strEmail)
Dim strArray As Variant
Dim strItem As Variant
Dim i As Long, c As String, blnIsItValid As Boolean
blnIsItValid = True
i = Len(strEmail) - Len(Application.Substitute(strEmail, "@", ""))
If i <> 1 Then IsEmailValid = False: Exit Function
ReDim strArray(1 To 2)
strArray(1) = Left(strEmail, InStr(1, strEmail, "@", 1) - 1)
strArray(2) = Application.Substitute(Right(strEmail, Len(strEmail) - Len(strArray(1))), "@", "")
For Each strItem In strArray
If Len(strItem) <= 0 Then
blnIsItValid = False
IsEmailValid = blnIsItValid
Exit Function
End If
For i = 1 To Len(strItem)
c = LCase(Mid(strItem, i, 1))
If InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 And Not IsNumeric(c) Then
blnIsItValid = False
IsEmailValid = blnIsItValid
Exit Function
End If
Next i
If Left(strItem, 1) = "." Or Right(strItem, 1) = "." Then
blnIsItValid = False
IsEmailValid = blnIsItValid
Exit Function
End If
Next strItem
If InStr(strArray(2), ".") <= 0 Then
blnIsItValid = False
IsEmailValid = blnIsItValid
Exit Function
End If
i = Len(strArray(2)) - InStrRev(strArray(2), ".")
If i <> 2 And i <> 3 Then
blnIsItValid = False
IsEmailValid = blnIsItValid
Exit Function
End If
If InStr(strEmail, "..") > 0 Then
blnIsItValid = False
IsEmailValid = blnIsItValid
Exit Function
End If
IsEmailValid = blnIsItValid
End Function
Run Code Online (Sandbox Code Playgroud)
有关如何查看说明,请访问http://www.vbaexpress.com/kb/getarticle.php?kb_id=281#instr