Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I built a script that users can input their email address and it works, unless the email address is like a lot of them are these days: me.you@mydom.com the me.you is showing up as invalid, can you please look at this and tell me what I did wrong?
if ($_f->{name} =~ /email/ && ($value =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^ +\.) / || $value !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{ +1,3})(\]?)$/)) { $_f->{errors} = "Invalid Email Address!"; $_errors++; }
I appreciate any advise you can give me.

Richard

Replies are listed 'Best First'.
Re: validating email address problem
by GrandFather (Saint) on Aug 17, 2007 at 05:08 UTC

    Modules such as Data::Validate::Email are the preferred way to do that trick.

    However if I take your code and make it into a runable sample:

    use strict; use warnings; my $value = 'me.you@mydom.com'; if ($value =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.) / || $value !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})( +\]?)$/ ) { print "Bad email\n"; } else { print "Good email\n"; }

    it prints:

    Good email

    which is not quite what you describe.


    DWIM is Perl's answer to Gödel
Re: validating email address problem
by bobf (Monsignor) on Aug 17, 2007 at 05:12 UTC
Re: validating email address problem
by McDarren (Abbot) on Aug 17, 2007 at 05:11 UTC