Check the Valid Email and Invalid Email Address in VB.NET

In this article, we will see how to check the Valid Email and Invalid Email Address in VB.NET.
  • 3430
 

In this article, we will see how to check the Valid Email and Invalid Email Address in VB.NET.

We will check email address throw the "www.webservicex.net" web service. We will add "http://www.webservicex.net/ValidateEmail.asmx" url in the web service.After that this service add in button click code.

Web.Config:- We will add appsetting in the web configuration. 

</configSections
  <
appSettings file="ValidEmail_net_webservicex_www_ValidateEmail">
    <add key="net.webservicex.www.ValidateEmail" value="http://www.webservicex.net/ValidateEmail.asmx"/>
  </appSettings>
<connectionStrings/>

This code is aspx:-

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Check the ValidEmail Address</title>
</head>
<
body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lableEmailAddress" runat="server" Text="EmailAddress"></asp:Label>
        &nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="textbox" runat="server" CausesValidation="True"></asp:TextBox>
        &nbsp;&nbsp;&nbsp;
        <asp:Button ID="CheckButton" runat="server" Text="CheckButton" OnClick="CheckButton_Click"/>
    </div>
    </form>
</body>
</
html>

This code is .VB:-

Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Text
Imports System.Net.Mail
Imports System.Text.RegularExpressions
Imports System.Data.SqlClient
-----------------------------------------------------------------------

Partial Class _Default
   Inherits System.Web.UI.Page
-----------------------------------------------------------------------  

 Protected Sub CheckButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckButton.Click
        Dim con As New SqlConnection("Data Source=MCNDESKTOP10; Initial Catalog=Data;Uid=sa; pwd=wintellect")
        Dim list_emails As New ArrayList()
        Dim i As Integer = 0
        Dim email As String
        con.Open()
        Dim cmd As New SqlCommand("Select EmailIDAddress from EmailAddress", con)
        Dim read_Email As SqlDataReader = cmd.ExecuteReader()
        While read_Email.Read()
            email = read_Email.GetValue(i).ToString()
            list_emails.Add(email)
            Dim cls As net.webservicex.www.ValidateEmail = New net.webservicex.www.ValidateEmail()
            Dim result As Boolean = cls.IsValidEmail(email)
        End While
        read_Email.Close()
        con.Close()
    End Sub
End Class
------------------------------------------------------------------------

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.