...

View Full Version : E-Mail Validation ??



wap3
09-02-2002, 01:02 PM
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 :thumbsup:

chrisvmarle
09-02-2002, 05:15 PM
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

Mouldy_Goat
09-02-2002, 05:19 PM
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:

unless ($fields{'Email'} =~ /(regex goes here)/) {
dienice("Dodgy email given");
}

To do the test..
Hope that helps a bit.

wap3
09-02-2002, 05:23 PM
Thanks

Yer that looks good, just want I wanted.

Thanks chrisvmarle & mouldy_goat

:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum