View previous topic :: View next topic |
Author |
Message |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Wed Jul 03, 2002 6:03 am Post subject: Basic Email Validation for CGI |
|
|
%%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 |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Jul 03, 2002 6:10 am Post subject: |
|
|
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 |
|
|
Dr. Dread Professional Member
Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Wed Jul 03, 2002 9:52 am Post subject: |
|
|
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 |
|
|
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Wed Jul 03, 2002 7:30 pm Post subject: |
|
|
All sorts of things can be added as we can see.
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.
-Garrett |
|
Back to top |
|
|
Sylvester Valued Newbie
Joined: 31 Jul 2000 Posts: 43 Location: Boston, MA USA
|
Posted: Wed Jul 03, 2002 9:22 pm Post subject: |
|
|
Hehe, bunch of showoffs! _________________ Sylvester
In the immortal words of the great philosopher, Homer ... "D'OH!!!" 8O |
|
Back to top |
|
|
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Thu Jul 04, 2002 7:37 am Post subject: |
|
|
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 |
|
|
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Thu Jul 04, 2002 7:38 am Post subject: |
|
|
I wonder if that IF statement is too long for VDS.... Hmmmm,
I just might have to give that a try tomorrow and see.
-Garrett |
|
Back to top |
|
|
SnarlingSheep Professional Member
Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Thu Jul 04, 2002 7:43 pm Post subject: |
|
|
Seems to work just fine for me. _________________ -Sheep
My pockets hurt... |
|
Back to top |
|
|
|
|
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
|
|