VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



E-Mail validation

by Pranabesh Sinha (1 Submission)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 15th July 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

E-Mail validation

API Declarations


Dim lenstr As String
Dim atchk As Boolean
Dim decchk As Boolean
Dim i As Integer
Dim strs As String
Dim stre As String
Dim rags As String
Dim hars As String
Dim strinat As String
Dim strindec As String
Dim strmidat As String
Dim strmiddec As String
Dim ans As String

Rate E-Mail validation



'**********************************************************
 'Email Validation: Allowed only small letters,numerals,@,.
 'Email format should be "[email protected]"
 'First checks for any @ Or . characters occures in string then
 'findis the last and first character of the string
 'finds "@." or ".@" are together then it is Correct Email format.
 'Otherwise it is wrong email format.
 '**********************************************************
Dim chkdec As String
Dim count1 As Integer
count1 = 0
    lenstr = Len(txt_email.Text)
    For i = 1 To lenstr
       chkdec = Mid(txt_email, i, (Len(txt_email) - ((lenstr) - 1)))
       If chkdec = "." Then
           count1 = count1 + 1
            If count1 >= 3 Then
              MsgBox "Wrong Email Format"
              txt_email.SetFocus
              Exit Function
            End If
        End If
    Next i
    atchk = InStr(1, txt_email.Text, "@")
    decchk = InStr(1, txt_email.Text, ".")
  If atchk = True And decchk = True Then
       For i = 1 To lenstr
         strs = Left(txt_email.Text, 1)
         stre = Right(txt_email.Text, 1)
         strinat = InStr(1, txt_email.Text, "@")
         strmidat = Mid(txt_email.Text, strinat, lenstr)
         strindec = InStr(1, txt_email.Text, ".")
         strmiddec = Mid(txt_email.Text, strindec, lenstr)
                 
         If Val(strinat) > Val(strindec) Then
              MsgBox "Wrong Email Format"
              txt_email.SetFocus
              Exit Function
         End If
         ans = Mid(txt_email, strindec, (Len(strindec) + 1))
         If ans = ".." Then
              MsgBox "Wrong Email Format"
              txt_email.SetFocus
              Exit Function
         End If
         rags = Mid(strmidat, 1, 2)
         hars = Mid(strmiddec, 1, 2)
        Next i
'         rags = Mid(Mid(txt_email.Text, InStr(1, txt_email.Text, "@"), lenstr), 1, 2)
'         hars = Mid(Mid(txt_email.Text, InStr(1, txt_email.Text, "."), lenstr), 1, 2)
        
        If strs = "@" Or stre = "." Or strs = "@" Or stre = "." Then
           MsgBox "Wrong Email Format"
           txt_email.SetFocus
           Exit Function
        ElseIf rags = "@." Or hars = ".@" Then
            MsgBox "Wrong Email Format"
             txt_email.SetFocus
            Exit Function
        End If

   Else
        MsgBox "Wrong Email Format"
        txt_email.SetFocus
            Exit Function

   End If

Download this snippet    Add to My Saved Code

E-Mail validation Comments

No comments have been posted about E-Mail validation. Why not be the first to post a comment about E-Mail validation.

Post your comment

Subject:
Message:
0/1000 characters