我有一个列,人们手动输入电子邮件地址。我想使用这个公式验证电子邮件地址:
=AND(FIND(“@”,A2),FIND(“.”,A2),ISERROR(FIND(” “,A2)))
但 Excel 弹出错误提示,表明你输入的公式包含错误。对我来说,这个公式看起来是正确的。你们有什么建议吗?
我有一个列,人们手动输入电子邮件地址。我想使用这个公式验证电子邮件地址:
=AND(FIND(“@”,A2),FIND(“.”,A2),ISERROR(FIND(” “,A2)))
但 Excel 弹出错误提示,表明你输入的公式包含错误。对我来说,这个公式看起来是正确的。你们有什么建议吗?
我在你的代码中遇到了同样的错误,似乎你没有使用“普通”的双引号,而是使用了不同的符号:"
。
尝试我的拼写: =AND(FIND("@",A2),FIND(".",A2),ISERROR(FIND(" ",A2)))
- 希望可以帮到你!
编辑:
此外,考虑使用=AND(NOT(ISERROR(FIND("@",A1))),NOT(ISERROR(FIND(".",A1))),ISERROR(FIND(" ",A1)))
,这将防止在缺少@
或.
时出现错误。尽管这仍将通过aaa@.
作为OK,但我认为即使采用这样直接的方法也有权被使用)
CODE
函数进行检查),而“plain”是具有代码34的字符。 - Peter L.FIND
函数将返回#VALUE!
,您也必须将其包装起来。 - Matteo在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
如需说明,请查看http://www.vbaexpress.com/kb/getarticle.php?kb_id=281#instr
firstname.lastname@domain@topdomain
的问题,我使用一个隐式的Like
修正了它并检查了正确的@
和.
的顺序。=AND(NOT(ISERROR(VLOOKUP("*@*.*",A2,1,FALSE))),ISERROR(FIND(" ",A2)))
编辑
"*?@?*.??*"
看起来更加描述性,只要顶级域名至少有两个字符长(截至本帖发布时,它们是这样的)。
=AND(IFERROR(FIND(".",A2),FALSE),IFERROR(FIND(".",A2,FIND("@",A2)),FALSE))
Function IsEmailValid(strEmail)
Dim i As Integer, emailPart As Variant
IsEmailValid = IsMadeOf(LCase(strEmail), "abcdefghijklmnopqrstuvwxyz0123456789.-_@")
emailPart = Split(strEmail, ".")
i = 0
While IsEmailValid And i <= UBound(emailPart)
IsEmailValid = Len(emailPart(i)) > IIf(i = UBound(emailPart), 1, 0)
i = i + 1
Wend
If IsEmailValid Then
emailPart = Split(strEmail, "@")
IsEmailValid = UBound(emailPart) = 1 And InStr(emailPart(UBound(emailPart)), ".") > 0
End If
End Function
Function IsMadeOf(str, charList)
Dim i As Long, c As String
IsMadeOf = True
For i = 1 To Len(str)
c = Mid(str, i, 1)
If InStr(charList, c) <= 0 Then
IsMadeOf = False
Exit Function
End If
Next i
End Function
“
字符更改为"
. - John Bustos