Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

excel email validation formula

Tags:

I have a column where people enter email address manually. I want to validate the email address using this formula:

=AND(FIND(“@”,A2),FIND(“.”,A2),ISERROR(FIND(” “,A2)))

but excel comes up with error that the formula you typed contains an error. For me the formula looks right. Do you guys have any suggestions?

like image 733
Hassan Ata Ullah Avatar asked Jan 23 '13 14:01

Hassan Ata Ullah


People also ask

How do I know if an email address is invalid?

It's important to understand that every valid email must contain an “@” symbol before the domain. An invalid email address will likely have spelling or formatting errors in the local part of the email or a “dead” domain name.


2 Answers

I got the same error for your code, and it appears that you have NOT "plain" double quotes, that is different from this symbol: ".

Try my spelling: =AND(FIND("@",A2),FIND(".",A2),ISERROR(FIND(" ",A2))) - hope will help!

EDIT:

In addition, consider to use =AND(NOT(ISERROR(FIND("@",A1))),NOT(ISERROR(FIND(".",A1))),ISERROR(FIND(" ",A1))) - that will prevent errors in case @ or . are missing. Still, this will pass as OK aaa@., but I suppose even such straightforward approach has rights to be used)

like image 58
Peter L. Avatar answered Oct 11 '22 23:10

Peter L.


Another way to validate emails in excel is using VBA code: see code below taken from http://www.vbaexpress.com/kb/getarticle.php?kb_id=281, it works great as is, and you can modify the code based on your needs.

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 

For how to instructions check http://www.vbaexpress.com/kb/getarticle.php?kb_id=281#instr

like image 23
Joel Avatar answered Oct 11 '22 23:10

Joel