Saturday, 1 August 2015

Validate Email in Vb.net

Public Function ValidateEmail(ByVal strEmail As String) As Boolean
        Dim strtmp As String, n As Long, sExt As String
        ValidateEmail = True

        If strEmail = "" Then
            ValidateEmail = False
            Exit Function
        ElseIf strEmail.ToLower.Contains("error") Then
            ValidateEmail = False
            Exit Function
        ElseIf strEmail.ToLower.Contains("eror") Then
            ValidateEmail = False
            Exit Function
        ElseIf strEmail.ToLower.Contains("websit") Then
            ValidateEmail = False
            Exit Function
        ElseIf strEmail.ToLower.Contains("webside") Then
            ValidateEmail = False
            Exit Function
        ElseIf strEmail.ToLower.Contains("webste") Then
            ValidateEmail = False
            Exit Function
        ElseIf strEmail.ToLower.Contains("webite") Then
            ValidateEmail = False
            Exit Function


        ElseIf strEmail.ToLower.Contains("wqebsite") Then
            ValidateEmail = False
            Exit Function


        ElseIf strEmail.ToLower.Contains("ebsite") Then
            ValidateEmail = False
            Exit Function

        ElseIf strEmail.ToLower.Contains("wesid") Then
            ValidateEmail = False
            Exit Function

        ElseIf strEmail.ToLower.Contains("wewbsite") Then
            ValidateEmail = False
            Exit Function

        ElseIf strEmail.ToLower.Contains("websitw") Then
            ValidateEmail = False
            Exit Function

        ElseIf strEmail.ToLower.Contains("websive") Then
            ValidateEmail = False
            Exit Function


        ElseIf strEmail.ToLower.Contains("websitw") Then
            ValidateEmail = False
            Exit Function
        ElseIf strEmail.ToLower.Contains("webit") Then
            ValidateEmail = False
            Exit Function
        ElseIf strEmail.ToLower.Contains("websi") Then
            ValidateEmail = False
            Exit Function


        ElseIf InStr(1, strEmail, "@") = 0 Then
            ValidateEmail = False
            Exit Function
        ElseIf InStr(1, strEmail, "@") = 1 Then
            ValidateEmail = False
            Exit Function
        ElseIf InStr(1, strEmail, "@") = Len(strEmail) Then
            ValidateEmail = False
            Exit Function
        ElseIf InStr(InStr(1, strEmail, "@") + 1, strEmail, "@") > 0 Then
            ValidateEmail = False
            Exit Function
        ElseIf InStr(1, strEmail, "@.") > 0 Then
            ValidateEmail = False
            Exit Function
        ElseIf Len(strEmail) < 6 Then
            ValidateEmail = False
            Exit Function
        End If
        sExt = ""
        If InStr(InStr(1, strEmail, "@"), strEmail, ".") <> 0 Then
            sExt = Right(strEmail, Len(strEmail) - InStr(InStr(1, strEmail, "@"), strEmail, "."))
        End If
        If sExt = "" Then
            ValidateEmail = False
            Exit Function
        End If

        strtmp = strEmail
        While InStr(1, strtmp, "@") <> 0
            n = 1
            strtmp = Right(strtmp, Len(strtmp) - InStr(1, strtmp, "@"))
        End While
        If n > 1 Then
            ValidateEmail = False
        End If
    End Function

No comments:

Post a Comment