Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-02-2002, 01:02 PM   PM User | #1
wap3
Regular Coder

 
Join Date: Aug 2002
Location: UK
Posts: 324
Thanks: 0
Thanked 0 Times in 0 Posts
wap3 is an unknown quantity at this point
E-Mail Validation ??

Hi I would like to know how I can validate the e-mail address submitted from my form. I have the following for some of the fields in my form to check if they are empty:

if ($fields{'County'} eq "") {
dienice("Please go back and enter your county. Then re-submit the form.");
}

How do I do it for an e-mail address so it checks if it has been entered properly, i.e. yourname@yahoo.com.
I done this in javascript before using regular expressions. But I have no idea in here.

Can anyone help ??

Thanks
wap3 is offline   Reply With Quote
Old 09-02-2002, 05:15 PM   PM User | #2
chrisvmarle
Regular Coder

 
Join Date: Jun 2002
Location: the Netherlands
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
chrisvmarle is an unknown quantity at this point
Try this one:

if($emailaddress !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) {
dienice("Please go back and enter your e-mail address right. Then re-submit the form.");
}

Hope that's enough...

Mzzl, Chris
chrisvmarle is offline   Reply With Quote
Old 09-02-2002, 05:19 PM   PM User | #3
Mouldy_Goat
Regular Coder

 
Join Date: Jul 2002
Location: London, UK
Posts: 126
Thanks: 0
Thanked 0 Times in 0 Posts
Mouldy_Goat is an unknown quantity at this point
Perl's best known features are its regular expressions, which are generally considered the best. I think I'm right in saying that JavaScript's regexes are little more than a copy, correct me if I'm wrong though..

You do pattern matching usually with the =~ operator. Here you'd use something like this:
Code:
unless ($fields{'Email'} =~ /(regex goes here)/) {
dienice("Dodgy email given");
}
To do the test..
Hope that helps a bit.
Mouldy_Goat is offline   Reply With Quote
Old 09-02-2002, 05:23 PM   PM User | #4
wap3
Regular Coder

 
Join Date: Aug 2002
Location: UK
Posts: 324
Thanks: 0
Thanked 0 Times in 0 Posts
wap3 is an unknown quantity at this point
Thanks

Yer that looks good, just want I wanted.

Thanks chrisvmarle & mouldy_goat

wap3 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:18 PM.


Advertisement
Log in to turn off these ads.