forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Basic Email Validation for CGI

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code
View previous topic :: View next topic  
Author Message
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Wed Jul 03, 2002 6:03 am    Post subject: Basic Email Validation for CGI Reply with quote

%%Email contains the email address being submitted to your form. The label "BadEmail" would be where you send the script to print whatever html back to the user to let them know that the email they are trying to submit is not valid.

This is only a basic email validation routine and it only checks to insure that the format of the email address being submitted is correct. If you want, from here you could go as far as adding DNS Lookup to see if the domain for the email address is valid.

Code:
  If @null(%%Email)
    Goto BadEmail
  End
  Option DecimalSep,.
  Option Fieldsep,@chr(64)
  Parse "%%PreAddy;%%SvrAddy",%%Email
  %%SvrDomain = @name(%%SvrAddy)
  %%SvrExtention = @ext(%%SvrAddy)
  If @null(%%PreAddy)
    Goto BadEmail
  End
  If @null(%%SvrDomain)
    Goto BadEmail
  End
  If @null(%%SvrExtention)
    Goto BadEmail
  End
Back to top
View user's profile Send private message
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Wed Jul 03, 2002 6:10 am    Post subject: Reply with quote

You can also stack these:
Code:

if @null(%%PreAddy)
   goto BadEmail
end
if @null(%%SvrDomain)
   goto BadEmail
end
if @null(%%SvrExtention)
   goto BadEmail
end

Into one IF/END like this:
Code:

if @null(%%PreAddy)@null(%%SvrDomain)@null(%%SvrExtention)
   goto BadEmail
end


Cheers, Mac

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Wed Jul 03, 2002 9:52 am    Post subject: Reply with quote

Here is a handful of routines for some more advanced email validation:

Code:

  REM Mail addresses cannot contain '.' and '@' next to each other
  If @greater(@pos(".@",%%email),0)@greater(@pos("@.",%%email),0)@greater(@pos("..",%%email),0)@greater(@pos("@@",%%email),0)
    Goto BadEmail
  End

  REM Email addresses do not start with '@' or '.'
  If @equal(@substr(%%email,1,),".")@equal(@substr(%%email,1,),"@")
   Goto BadEmail
  End

  REM Email addresses cannot contain '_', '~' or '#' after the @ sign.
  If @greater(@pos("_",%%SvrAddy),0)@greater(@pos("~",%%SvrAddy),0)@greater(@pos("#",%%SvrAddy),0)
   Goto BadEmail
  End
 
  REM Email addresses don't start with 'www' - that's web page addresses
  REM This one is a bit wacky - mail addresses may actually have www at the start
  REM but it's rare and probably the most common mistake that people make
  If @equal(@substr(%%email,1,3),www)
   Goto BadEmail
  End
 
  REM Email accounts cannot contains commas or spaces
    If @greater(@pos(" ",%%Email),0)@greater(@pos(",",%%Email),0)
    Goto BadEmail
  End

  REM The top-level domain must be at least 2 chars long
  If @not(@greater(@len(%%SvrExtention),1))
    Goto BadEmail
  End


Greetz
Dr. Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing


Last edited by Dr. Dread on Thu Dec 12, 2002 9:03 am; edited 1 time in total
Back to top
View user's profile Send private message
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Wed Jul 03, 2002 7:30 pm    Post subject: Reply with quote

All sorts of things can be added as we can see. Smile

And even with all that, you could still add DNS Lookup to insure that the domain given isn't bogus.

Gotta love VDS! It's just too easy sometimes. Smile


-Garrett
Back to top
View user's profile Send private message
Sylvester
Valued Newbie


Joined: 31 Jul 2000
Posts: 43
Location: Boston, MA USA

PostPosted: Wed Jul 03, 2002 9:22 pm    Post subject: Reply with quote

Hehe, bunch of showoffs! Laughing
_________________
Sylvester

In the immortal words of the great philosopher, Homer ... "D'OH!!!" 8O
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Thu Jul 04, 2002 7:37 am    Post subject: Reply with quote

Ok, to summerize today's lesson in VDS coding, we simplify
and combine all the tips given:

Code:
  If @null(%%Email)
    Goto BadEmail
  End
  Option DecimalSep,.
  Option Fieldsep,@chr(64)
  Parse "%%PreAddy;%%SvrAddy",%%Email
  %%SvrDomain = @name(%%SvrAddy)
  %%SvrExtention = @ext(%%SvrAddy)

  If @null(%%PreAddy)@null(%%SvrDomain)@null(%%SvrExtention)@not(@greater(@len(%%SvrExtention),1))@greater(@pos(" ",%%Email),0)@greater(@pos(",",%%Email),0)@greater(@pos("_",%%SvrAddy),0)@greater(@pos("~",%%SvrAddy),0)@greater(@pos("#",%%SvrAddy),0)@equal(@substr(%%email,1,),".")@equal(@substr(%%email,1,),"@") @greater(@pos(".@",%%email),0)@greater(@pos("@.",%%email),0)@greater(@pos("..",%%email),0)@greater(@pos("@@",%%email),0)
   goto BadEmail
  End


Thanks to Mac and Dr. Dread for their tips and added code.

I did leave out the checking for www though since there is a
chance that someone's email address just might have www
in it.

-Garrett
Back to top
View user's profile Send private message
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Thu Jul 04, 2002 7:38 am    Post subject: Reply with quote

I wonder if that IF statement is too long for VDS.... Hmmmm,
I just might have to give that a try tomorrow and see. Wink


-Garrett
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Thu Jul 04, 2002 7:43 pm    Post subject: Reply with quote

Seems to work just fine for me.
_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group