in reply to regexp to only allow for formally valid email addresses

Use Mail::RFC822::Address. Also, the Regular Expression Library has some pretty interesting constructs.

As to your regex, I don't see anything wrong in it, and it works with a couple of test cases as it should:

$ perl -e 'print "valid\n" if ("foo\@bar" =~ m/^[a-zA-Z_\-.0-9]+@[a-zA +-Z_\-.0-9]+$/);' valid $ perl -e 'print "valid\n" if ("j.random.hacker\@perlmonks.com" =~ m/^ +[a-zA-Z_\-.0-9]+@[a-zA-Z_\-.0-9]+$/);'

Of course, tests can never show the absence of errors. But I'm willing to bet you have a problem somewhere else in the program.

UPDATE: Seems like others beat me to it... I just remembered that there was some nice discussion about this over at The Daily WTF.

--
print "Just Another Perl Adept\n";

Replies are listed 'Best First'.
Re^2: regexp to only allow for formally valid email addresses
by fraktalisman (Hermit) on Mar 08, 2007 at 08:26 UTC
    vrk wrote:
    Of course, tests can never show the absence of errors. But I'm willing to bet you have a problem somewhere else in the program.

    If we had bet, you'd won ;)
    There was another parameter that goes into the email header. The $f{'Email'} field validation was not the actual problem ...