no i don't. just the examples from above which contain spacing, no @, and must have a period after the @
no i don't. just the examples from above which contain spacing, no @, and must have a period after the @
Heres a function that can be used to check valid e-mail address
![]()
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
Regards
Sean
Please add to my reputation if you think i helped (click on the star below the post)
Mark threads as "Solved" if you have your answer (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [code]
Please supply a workbook containing example Data: It makes its easier to answer your problem & saves time!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks