To read the article online, visit

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 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
    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:

Article Information
Article Title: Email Validation Routine
Article Author: João Vieira
Published Date: Sunday, April 11, 1999
Article URL:

Copyright 2019 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers