email validation?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

is there a built-in function in Excel that tells whether a text string is a
valid email? (I don't mean whether the address exists or not, but rather if
it has exactly one "@" in it, then some letters, then a ".", some more
letters, etc)

I can build one, but before I do...

----------------
This post is a suggestion for Microsoft, and Microsoft responds to the
suggestions with the most votes. To vote for this suggestion, click the "I
Agree" button in the message pane. If you do not see the button, follow this
link to open the suggestion in the Microsoft Web-based Newsreader and then
click "I Agree" in the message pane.

http://www.microsoft.com/office/com...7-bcd80de8a211&dg=microsoft.public.excel.misc
 
There is no built-in way to do this. Try

Dim S As String
S = "(e-mail address removed)"
If S Like "?*@?*.?*" Then
Debug.Print "OK"
Else
Debug.Print "Not ok"
End If



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


message
news:[email protected]...
 
This one is better than my previous reply:

If Len(S) - Len(Replace(S, "@", "")) = 1 Then
If S Like "?*@?*.?*" Then
Debug.Print "OK"
Else
Debug.Print "Not ok"
End If
Else
Debug.Print "not ok"
End If
 
I ended up just going with the function:

=IF(OR(ISERROR(FIND("@",M14)),ISERROR(FIND(".",RIGHT(M14,LEN(M14)-FIND("@",M14))))),"invalid",IF(AND(FIND("@",M14)>1,ISERROR(FIND("@",RIGHT(M14,LEN(M14)-FIND("@",M14)))),FIND(".",RIGHT(M14,LEN(M14)-FIND("@",M14)))>1,FIND(".",RIGHT(M14,LEN(M14)-FIND("@",M14)))<LEN(M14)-FIND("@",M14)),"valid","invalid"))
 
I use this UDF


'-----------------------------------------------------------------
Public Function ValidEmail(Adress As String) As Boolean
'-----------------------------------------------------------------
Dim oRegEx As Object
Set oRegEx = CreateObject("VBScript.RegExp")
With oRegEx
.Pattern = "^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$"
' .Pattern = "^(\w+\.)*(\w+)@(\w+\.)+([a-zA-Z]{2,4})$"
ValidEmail = .Test(Adress)
End With
Set oRegEx = Nothing
End Function


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
Back
Top