Validate email address

ASP.NET

    Next

  • 1. Where can I download Treeview control? No longer on MSDN site?
    Hey all, MS used to have an unsupported web controls .exe that they made available for downloading on their site. It appears to no longer be there. Anyone know where I could get a copy? Also, if anyone can suggest a great Treeview (of any sort) that allows for binding to sql server and editing of childs, please let me know! Thanks!
  • 2. Enter Key H*ll, control enter key submit button
    Hi VB.Net code Behind, Web form. I am looking for a way to stop my web form application from firering a button click when the user hits the Enter key. I only want to button to bubmit, or exit or clear when they click the button not in random when they hit the enter key. Thanks for the help. BrianDH

Re: Validate email address

Postby Ken Cox [Microsoft MVP] » Wed, 13 Aug 2003 10:00:53 GMT

Hi Michael,

You can confirm the domain name by doing a Whois search. There's some code here
for doing that.

 http://www.**--****.com/ 

 http://www.**--****.com/ 

Ken





I have a web form that collects the users email address.

How can I validate the email address, at the very least confirm that the
domain exists?

Thanks

-- 
Michael Tissington
Oaklodge Technologies
 http://www.**--****.com/ 





Re: Validate email address

Postby vMike » Thu, 14 Aug 2003 03:10:37 GMT

This is what I use. I don't know if it is foolproof or not but I haven't had
any problems with it.
in my aspx page
<asp:textbox id="Email1" size="40" runat="server"/>

                       <asp:RegularExpressionValidator id="RequiredEmail1"
runat="server"
                  ControlToValidate="Email1"
                            InitialValue=""

ValidationExpression="[a-zA-Z_0-9.]+@[a-zA-Z_0-9.]+\.(com|net|org|edu|mil)$"
                  Display="Static"
                  Font-Name="verdana" Font-Size="10pt">
                     * valid e-mail address required
          </asp:RegularExpressionValidator>
                        <asp:CustomValidator id="CustomValidator1"
runat="server"
              ControlToValidate="Email1"
           OnServerValidate="ServerValidate"
                            Display="Static"
                            Font-Name="verdana" Font-Size="10pt">
                             * valid mail server name required.
                        </asp:CustomValidator>


 in my codebehind page.

Sub ServerValidate (sender As Object, dnsvalue As ServerValidateEventArgs)
            dim strDomain as string
            dnsvalue.IsValid = False
            Try
                dim int as integer
                int = instr(2,dnsvalue.Value,"@")
                strDomain = mid(dnsvalue.value,int+1,999)
                If not Dns.GetHostByName(strDomain).hostname is null Then
                    dnsvalue.IsValid = True
                End If
            Catch
            End Try
            RequiredEmail1.text = ""

 End Sub









Re: Validate email address

Postby vMike » Thu, 14 Aug 2003 09:24:06 GMT

Thanks for the suggestion. I'm still trying to figure the syntax but it
seems to work great. I find these expression a bit of a challenge!




@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA






Re: Validate email address

Postby vMike » Thu, 14 Aug 2003 10:07:56 GMT

Let see if I got this right.
^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z
]{2,4}|[0-9]{1,3})(\]?)$
is

^  is start with
[w-\.] is basically anything
then @
then either
First side
1) 3- 1 to 3 digit numbers separated by a . plus . (I guess this is for
using an ip address) or

2) \w is any word or words plus .
plus
second side
either
1) 2-4 letters or

2) 1-3 numbers
the $ is the end

The parts I don't understand are
why is there a - after the each w and why the two w's are different (seem
like the second w should be the same as the first set.
what does the (\]?) mean.








@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA



the



Re: Validate email address

Postby Ed Courtenay » Thu, 14 Aug 2003 18:10:52 GMT

It breaks down like this:

([\w-\.]+) : One or more words separated by hyphens or full stops
@ : The '@' symbol (never... ;)
(\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.) : The first three segments of a
dotted ip address preceded by a '['
(([\w-]+\.)+)) : At least one subdomain (word) followed by a full stop
[a-zA-Z]{2,4} : Two to four characters in the range a - z (case insensitive)
[0-9]{1,3})(\]?) : The last portion of a dotted ip address followed by an
optional ']' character

I have to admit that it seems a bit odd that the final ']' is optional and
not required. I'd have to check the RFC on email addresses to check that
one.

Personally, I would have rewritten it as:

^([\w-\.]+)@(\[(\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.){3}[0-9]{1,3}\])|((([
\w-]+\.)+))[a-zA-Z]{2,4})$

Bear in mind this might not work - I've not had a chance to test it yet!






^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z






@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA






RE: Validate email address

Postby lukezhan » Fri, 15 Aug 2003 15:46:41 GMT

Here is a web which collects all helpful information on this issue 
(including Whois, regular expression...), you may take a look at it:

 http://www.**--****.com/ 

Luke

"Microsoft Security Announcement: Have you installed the patch for 
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises 
you to review the information at the following link regarding Microsoft 
Security Bulletin MS03-026 
 http://www.**--****.com/ 
visit Windows Update at  http://www.**--****.com/  to install the 
patch.  Running the SCAN program from the Windows Update site will help to 
insure you are current with all security patches, not just MS03-026."


Similar Threads:

1.Code for validating email address in C# - validate email

Here's a small method for validating email in C#. It may save you some time..

public static bool IsValidEmailAddress(string sEmail)
{
  if (sEmail == null)
  {
    return false;
  }

  int nFirstAT = sEmail.IndexOf('@');
  int nLastAT  = sEmail.LastIndexOf('@');

  if ( (nFirstAT > 0) && (nLastAT == nFirstAT) && 
       (nFirstAT < (sEmail.Length - 1)) )
  {
    // address is ok regarding the single @ sign
    return (Regex.IsMatch(sEmail, @"(\w+)@(\w+)\.(\w+)"));
  }
  else
  {
    return false;
  }
}

2.dns lookup from .net -- validate email address (domain)

Hi,

I would like to validate an email address from .net. Now before you scream
regular expression I would like something a bit better than this.

I would like to validate the domain, and maybe lookup to see if the domain
has a valid MX record.

can anybody tell me if this is possible using .net and if so point me in the
right direction.

If it is possible then would it also be possible to make sure that I get an
authorative answer and not just an answer from any old server.

many thanks in advance.

martin.




3.Help validating email addresses

I am using a RegularExpressionValidator control on my ASP page, and I have 
the ValidationExpression property set to "Internet E-mail Address".  The 
email address is valiated when the user puts in a email addess in the TextBox.

This works fine until I have multiple email addresses.  How can I validate 
multiple e-mail addresses seperated by a "," or ";"?  The following 
ValidationExpression will validate up to 2 email addresses but not anymore:

\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*

Any suggestion would be helpful.  The number of emails could be infinite, 
but I think the max will be 10 at most.

Thanks,

4.Validating Email address with System.Text.RegularExpressions.RegEx

I'm a little confused by this functionality.  It doesn't seem to be
behaving like it should.

I am using the following regular expression to validate email
addresses:
"\w+([-+.]\w+)*@\w+([-.]\w+)*\.([a-zA-Z]{2,4})\040*".  From what I can
determine it should validate the following rules:

1.  BEFORE THE AMPERSAND
    A.  Must contain at least one alphanumeric character.
    B.  Can contain a '-', '+', or '.' character but if it does it
must have a alphanumeric character on either side of it.
2.  AFTER THE AMPERSAND BUT BEFORE THE '.'
    A.  Must contain at least one alphanumeric character.
    B.  Can contain a '-', or '.' character but if it does it must
have a alphanumeric character on either side of it.
3.  AFTER THE '.'
    A.  Must contain at least two alphabetical characters but no more
than 4.

However when I use System.Text.RegularExpressions.RegEx with this
expression and use the IsMatch method and use an email address like
 XXXX@XXXXX.COM @ XXXX@XXXXX.COM  it returns true as if that was
a valid email address based on the rules.

Doesn't the {2,4} mean that it has to have a minimum of 2 characters
after the '.' character but no more than 4?  Also, doesn't the
[a-zA-Z] mean that the characters after the '.' must be alphabetical
only?  My tests seem to prove otherwise.

Any help on this would be great...thanks!

5.Validating email addresses using System.Text.RegularExpressions

I'm a little confused by this functionality.  It doesn't seem to be
behaving like it should.

I am using the following regular expression to validate email
addresses:
"\w+([-+.]\w+)*@\w+([-.]\w+)*\.([a-zA-Z]{2,4})\040*".  From what I can
determine it should validate the following rules:

1.  BEFORE THE AMPERSAND
    A.  Must contain at least one alphanumeric character.
    B.  Can contain a '-', '+', or '.' character but if it does it
must have a alphanumeric character on either side of it.
2.  AFTER THE AMPERSAND BUT BEFORE THE '.'
    A.  Must contain at least one alphanumeric character.
    B.  Can contain a '-', or '.' character but if it does it must
have a alphanumeric character on either side of it.
3.  AFTER THE '.'
    A.  Must contain at least two alphabetical characters but no more
than 4.

However when I use System.Text.RegularExpressions.RegEx with this
expression and use the IsMatch method and use an email address like
 XXXX@XXXXX.COM @ XXXX@XXXXX.COM  it returns true as if that was
a valid email address based on the rules.

Doesn't the {2,4} mean that it has to have a minimum of 2 characters
after the '.' character but no more than 4?  Also, doesn't the
[a-zA-Z] mean that the characters after the '.' must be alphabetical
only?  My tests seem to prove otherwise.

Any help on this would be great...thanks!

6. Validate email address

7. Validate Email Address Using Regular Expressions

8. validate email address in input textbox



Return to ASP.NET

 

Who is online

Users browsing this forum: No registered users and 95 guest