When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Sunday, April 11, 1999

An Email Validation Routine
By João Vieira



This code will test to make sure that an email address entered by a user is a valid email address.
1. First I have created a variable called goby. If goby equals one, then the validation is ok; otherwise goby will equal 0.

2. The function InStr will be used to determine if a certain character is inside the email string.

3. Here is the code, use

- continued -

it as you want. Happy Programming!

<%

Dim goby
goby = 0 'Initializing goby to 0

'if the len is less than 5 then it can't be an email
'(i.e.: a@a.c)
If Len(session("emailfrom")) <= 5 Then
   goby = 1
End If

If InStr(1, session("emailfrom"), "@", 1) < 2 Then
    'If we find one and only one @, then the
    'email address is good to go.
    goby = 1
Else
    If InStr(1,session("emailfrom"), ".", 1) < 4 Then
        'Must have a '.' too
        goby = 1
    End If
End If

If goby <> 0 then
    'Well , if goby <> 0 then something
    'must be wrong
    response.write "Bad E-Mail..."
End If

%>



Note from Scott Mitchell
The above script shows one way to validate an email address: using ASP on the server. You can also use JavaScript on the client's side, by writing client-side scripting. An example of email validation (as well as many other types of validation) using JavaScript, can be found here:


João Vieira BIO: (email me!)
- Age : 23
- Student And worker (tryin' to finish university, on the last year of the graduation)
- Workin' now at NetGate Portugal
- Programming little stuff since 1989
- Programming HTML since 1996
- Programming JavaScript since 1997, made some experiences with Java.
- Programming ASPs since the Summer of 1997 (yeap, I didn't had nothing to do. Now I love it.)
- Programming ActiveX since 1998
- Webmaster of www.joaovieira.com


ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article