Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: regexp to only allow for formally valid email addresses

by vrk (Chaplain)
on Mar 07, 2007 at 17:53 UTC ( #603656=note: print w/replies, xml ) Need Help??


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 ...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://603656]
help
Chatterbox?
LanX oh my god it's full of hacks!!! ...
[holli]: what? the pm code you swindled your way into?
[LanX]: no already the pm code I'm allowed to see ... http://www. perlmonks.net/ index.pl?node_id= 1203338;style=css
[LanX]: understanding this code is like relearning space invaders and donkey Kong at the same time

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2017-11-20 21:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (294 votes). Check out past polls.

    Notices?