//  home   //  advanced search   //  news   //  categories   //  sql build chart   //  downloads   //  statistics
 ASP FAQ 
Home
ASP FAQ Tutorials

   8000XXXX Errors
   Alerts
   ASP.NET 2.0
   Classic ASP 1.0
      COM / ActiveX Components
      Forms
      General Topics
      Date/Time Routines
      Email Scripts & Info
      Files/Directories & FSO
   Databases
   General Concepts
   Search Engine Optimization (SEO)

Contact Us
Site Map

Search

Web
aspfaq.com
tutorials.aspfaq.com
classicasp.aspfaq.com

ASP FAQ Tutorials :: Classic ASP 1.0 :: Email Scripts & Info :: How do I validate an e-mail address?


How do I validate an e-mail address?

You can use ASP to validate the *format* of an e-mail address, but not necessarily that it is a valid and working address. Here is a rather concise script using regular expressions (thanks again to Chris Hohmann for his useful RE input): 
 
<% 
    Function isEmailValid(email) 
        Set regEx = New RegExp 
        regEx.Pattern = "^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w{2,}$" 
        isEmailValid = regEx.Test(trim(email)) 
    End Function 
 
' now, test it: 
 
    Function testEmail(email) 
        response.write "<p>" & email & " (" & _ 
            isEmailValid(email) & ")" 
    End Function 
 
    testEmail("bob") 
    testEmail("aaron@!whatever.com") 
    testEmail("aaron@whatever.com") 
%>
 
And in JScript: 
 
<script language="JavaScript" runat="SERVER"> 
function isEmailValid(email) 

    return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w{2,}$/.test(email); 

 
// now, test it: 
 
function testEmail(email) 

    Response.Write("<p>" + email + " (" + isEmailValid(email) + ")"); 

 
testEmail("bob"); 
testEmail("aaron@!whatever.com"); 
testEmail("aaron@whatever.com"); 
</script>
 
For testing that the e-mail is actually valid (and not just in an acceptable format), you may want to generate some random string or a key, e-mail it to the user, and have them enter it into your interface. You can match the random string in your database to verify that it is the same string they were sent, therefore you know that the e-mail address is valid.

Related Articles

Can I get CDO messages to return a read receipt?
Can I use a remote SMTP server with CDONTS.NewMail?
How do I alter the priority / importance of an e-mail message?
How do I prevent my links from wrapping in an e-mail?
How do I put carriage returns into an e-mail?
How do I send e-mail from ASP?
How do I send e-mail from SQL Server?
How do I send e-mail in HTML format?
How do I send e-mail with CDO?
Should I use form action=mailto: to mail the results of a form?
Where can I get more details about configuring / using CDO?
Why can't ASP handle 80,000 e-mails?
Why do CDONTS messages end up in the badmail folder?
Why do I get 8000900F errors?
Why do I get 80040108 errors?
Why do I get 8004020A errors?
Why do I get 80090020 errors?
Why do I get C00402CE / C00402C7 errors?
Why does CDO.Message give 800C000D errors?
Why does CDO.Message give me 8004020F errors?
Why does CDO.Message give me 80040213 errors?
Why does CDO.Message give me 80040222 errors?
Why does my CDONTS mail hang out in the queue or pickup folders?
Why is e-mail to certain domains being rejected?

 

 


Created: 1/8/2002 | Last Updated: 2/26/2005 | broken links | helpful | not helpful | statistics
© Copyright 2006, UBR, Inc. All Rights Reserved. (333)

 

Copyright 1999-2006, All rights reserved.
Finding content
Finding content.  An error has occured...