Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
MSIL
If Page.IsValid Then
           Try
               Dim sfbEmailValidator As New EmailValidator()
               If txtFromDomain.Text.Length > 0 Then
                   sfbEmailValidator.SmtpHeloDomain = txtFromDomain.Text
               End If
               If txtSmtpPort.Text.Length > 0 Then
                   sfbEmailValidator.SmtpPort = Integer.Parse(txtSmtpPort.Text)
               End If
               If txtSmtpMail.Text.Length > 0 Then
                   sfbEmailValidator.SmtpFromEmail = txtSmtpMail.Text
               End If
               If txtDnsServer.Text.Length > 0 Then
                   sfbEmailValidator.DnsServers.Add(txtDnsServer.Text)
               End If
               sfbEmailValidator.ValidationLevel = DirectCast(Integer.Parse(ddlValidationLevel.SelectedValue), ValidationLevel)
               sfbEmailValidator.Validate(txtEmail.Text)



               lblResult.Text = sfbEmailValidator.SmtpTranscript.Replace("" & Chr(13) & "" & Chr(10) & "", "<br>")
           Catch exc As Exception
               lblResult.Text = "An exception occurred: " + exc.Message
           End Try
       End If
   End Sub



i am using above code to validate email address ?

where tell how we can find the valid email address you can say that result .
this mail is valid or not plz help me
Posted

Try using a RegularExpressionValidator on the page. This link[^] will get you started.
 
Share this answer
 
Comments
RaviRanjanKr 27-May-11 5:15am    
Perfect Solution, My 5 :)
Kiran Sonawane 27-May-11 5:37am    
my 5 +
u can do validation from javascript also.

see this link

http://www.tizag.com/javascriptT/javascriptform.php[^]
 
Share this answer
 
Use following functions for email validation. this will also validate domain values.. e.g. below functions will only validate emails having yahoo.com and gmail.com as domains.

SQL
function validate()
    {

C#
var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+$/;
            //alert(pattern.test(Email));
            if(!pattern.test(Email))
            {
                alert("Enter a valid E-mail ID.");
                //loadXML('1008');
                document.getElementById('<%=txtEmail.ClientId %>').value ="";
                document.getElementById("<%=txtEmail.ClientId %>").focus();
                return false;
            }
            var res = isValidDomain();
            if (res==0)
            {
              return false;
            }



}

C#
function isValidDomain()
    {
      var Domain = "yahoo.com;gmail.com";
      var DomainList=Domain.split(",");
      var Email = document.getElementById("<%=txtEmail.ClientId %>").value;
      var userDomains = Email.split("@");
            var userDomain=userDomains[1]
            var part_num=0;
            var result=0;
            while (part_num < DomainList.length)
            {
              var srtdomain = DomainList[part_num];
              part_num+=1;
              if (srtdomain.toUpperCase()==userDomain.toUpperCase())
              {
                result=1;
                break;
              }
            }
            if (result==0)
            {
                var email = document.getElementById("<%=txtEmail.ClientId %>")
                email.disabled=false;
                alert("Enter a valid Domain Name.");
                document.getElementById("<%=txtEmail.ClientId %>").focus();
            }
            return result;
       }
 
Share this answer
 
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
                    ValidationGroup="vgroup" runat="server" ControlToValidate="yourtextbox" Display="Dynamic"
                    ErrorMessage="Plese enter valid email address." ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>


Add this and replace "yourtextbox" in ControlToValidate with your textbox.
Also set the validationGroup = "yourgrouphere". you are done

...Cheer's
 
Share this answer
 
v2
Comments
Nilesh G Umaretiya 27-May-11 6:03am    
This code is know everybody. Make different.... My Dear.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900