Click here to get back home

Trying to catch invalid emails

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Trying to catch invalid emails Samik R. 05-06-2008
Posted by Samik R. on May 6, 2008, 10:58 pm
Please log in for more thread options
Hello,
I use the following regular expression to catch typical invalid email
addresses:
------------
my @Email=("sam._\@abc.org", "sam_.\@abc.org", "sam_.\@abc.org");
foreach (@Email)
{

if(/^[A-z0-9]+([_\.][A-z0-9\-]+)*[@][A-z0-9_\-]+([.][A-z0-9_\-]+)?\.[A-z]$/)
{ print "$_ is a valid email id\n"; }
else
{ print "$_ is an invalid email id\n"; }
}
-------------

This expression does not catch the above 3 emails in the array (the
program says that they are valid emails).

Can someone help me to discard these three?
Thanks.

Posted by Ron Bergin on May 6, 2008, 11:13 pm
Please log in for more thread options
> Hello,
> I use the following regular expression to catch typical invalid email
> addresses:
> ------------
> my @Email=("sam._\@abc.org", "sam_.\@abc.org", "sam_.\@abc.org");
> foreach (@Email)
> {
>
>
if(/^[A-z0-9]+([_\.][A-z0-9\-]+)*[@][A-z0-9_\-]+([.][A-z0-9_\-]+)?\.[A-z]$/)
> { print "$_ is a valid email id\n"; }
> else
> { print "$_ is an invalid email id\n"; }}
>
> -------------
>
> This expression does not catch the above 3 emails in the array (the
> program says that they are valid emails).
>
> Can someone help me to discard these three?
> Thanks.

Try using the Email::Valid module.

use strict;
use warnings;
use Email::Valid;

my @Email=("sam._\@abc.org", "sam_.\@abc.org", "sam_.\@abc.org");

foreach my $address (@Email)
{
print Email::Valid->address($address) ? "$address valid\n" :
"$address not valid\n";
}

Posted by Ben Morrow on May 6, 2008, 11:41 pm
Please log in for more thread options

> Hello,
> I use the following regular expression to catch typical invalid email
> addresses:

Don't do that. Use a module, such as Email::Valid, that actually gets it
right.

Ben


Posted by Ben Bullock on May 6, 2008, 11:56 pm
Please log in for more thread options

> if(/^[A-z0-9]+([_\.][A-z0-9\-]+)* ...

The problem is A-z here, A-z contains all of

ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz

so it matches the underscore in the email address.

To match only letters, you should use [A-Za-z0-9] instead.

Posted by Abigail on May 7, 2008, 4:11 am
Please log in for more thread options
_
Samik R. (samik@frKKshKll.org) wrote on VCCCLXIII September MCMXCIII in
:) Hello,
:) I use the following regular expression to catch typical invalid email
:) addresses:
:) ------------
:) my @Email=("sam._\@abc.org", "sam_.\@abc.org", "sam_.\@abc.org");
:) foreach (@Email)
:) {
:)
:)
if(/^[A-z0-9]+([_\.][A-z0-9\-]+)*[@][A-z0-9_\-]+([.][A-z0-9_\-]+)?\.[A-z]$/)
:) { print "$_ is a valid email id\n"; }
:) else
:) { print "$_ is an invalid email id\n"; }
:) }
:) -------------
:)
:) This expression does not catch the above 3 emails in the array (the
:) program says that they are valid emails).
:)
:) Can someone help me to discard these three?


Sure.

if (/_/) {
print "$_ is invalid";
}
else {
print "$_ is valid";
}



Abigail
--
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
|perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
|perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
|perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;

Similar ThreadsPosted
Trying to catch invalid emails June 10, 2008, 12:08 am
Help with Sending Multiple Emails! October 6, 2004, 2:54 pm
deciphering emails in PERL October 21, 2004, 9:54 pm
Saving attachments from emails October 22, 2004, 12:25 pm
How to generate random emails? February 24, 2005, 11:35 am
Receiving emails with attachments April 8, 2006, 2:26 pm
GD::Graph Invalid Data from DBI July 10, 2005, 12:28 am
XML::LibXML findnodes Invalid Expression September 10, 2005, 8:13 am
Invalid length of line read.... April 26, 2006, 2:36 am
Archive::Zip - zip file has "invalid" format October 5, 2006, 9:41 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap