Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Email Addy Validation

Status
Not open for further replies.

scaifea

Technical User
Apr 14, 2005
35
0
0
GB
I am struggling with my simple perl validation of email addresses in a "refer a friend" type script.

I have the line ..

if ($email1 !~ /.*\@.*\..*/) {
print "Content-type: text/html\n\n";
&header;
print "<span class=\"title\">Please Enter A Valid Friend Email 1 Address!</span><a href=\"javascript:history.back(-1)\" class=\"backlink\">Back to Form</a>\n";
exit;
}

But I keep getting an error on all email address types I try, can anyone help me out?

Thanks
 
Validating emails with your own regexp is a nightmare. You'll save yourself a lot of time, effort and frustration if you use the Email::Valid module.

Validation becomes simply:
Code:
use Email::Valid;

if ( Email::Valid->address( $some_email_address ) ) {
   print "It's valid!\n";
}
else {
   print "It's not :-(\n";
}
 
Are there other modules or pre-tested regexes for the other common form fields like phone number, last name address etc?
I can't seem to find anything beyond how to construct regexes.
I don't really trust my skills that much yet, especially knowing about cases like lastname = O'reilly
 
Thanks, thats helpful.

Are there any lists of example regexes that I can use when a module is overkill? (besides all the bad examples I've seen)
I also noticed that Data::FormValidator did'nt have a name checker. Like I said, I would never have thought of the O'reilly name problem.
Oreilly or "invaild last name" won't please users
(Memory and disk space is cheap now, why am I still Christophe instead of Christopher, annoys me everytime)

I'd rather just learn the right answers for the everyday stuff and make my own for the special stuff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top