Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trying to catch invalid emails

0 views
Skip to first unread message

Samik R.

unread,
May 6, 2008, 10:58:25 PM5/6/08
to
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]{2,3}$/)
{ 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.

Ron Bergin

unread,
May 6, 2008, 11:13:48 PM5/6/08
to

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";
}

Ben Morrow

unread,
May 6, 2008, 11:41:38 PM5/6/08
to

Quoth "Samik R." <sa...@frKKshKll.org>:

> 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

Ben Bullock

unread,
May 6, 2008, 11:56:52 PM5/6/08
to
Samik R. <sa...@frkkshkll.org> wrote:

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

Abigail

unread,
May 7, 2008, 4:11:00 AM5/7/08
to
_
Samik R. (sa...@frKKshKll.org) wrote on VCCCLXIII September MCMXCIII in
<URL:news:fvr60f$pqd$1...@aioe.org>:
:) 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]{2,3}$/)
:) { 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/=/./;

Frank Seitz

unread,
May 7, 2008, 5:09:24 AM5/7/08
to

An e-mail address with _ (or ._ or _.) isn't invalid, AFAIK.

Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Abigail

unread,
May 7, 2008, 6:00:49 AM5/7/08
to
_
Frank Seitz (devnu...@web.de) wrote on VCCCLXIII September MCMXCIII in
<URL:news:68d9vaF...@mid.individual.net>:


But that wasn't what he asked.

He wanted to filter out three particular email addresses.

Abigail
--
my $qr = qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";

Gordon Etly

unread,
May 7, 2008, 8:57:47 PM5/7/08
to
Abigail wrote:
> _
> Frank Seitz (devnu...@web.de) wrote on VCCCLXIII September
> MCMXCIII in <URL:news:68d9vaF...@mid.individual.net>:
> ;; Abigail wrote:
> ;; > _
> ;; > Samik R. (sa...@frKKshKll.org) wrote on VCCCLXIII September
> :: > :) MCMXCIII in ;; > <URL:news:fvr60f$pqd$1...@aioe.org>:

> ;; > :) 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]{2,3}$/)
> ;; > :) { 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";
> ;; > }
> ;;
> ;; An e-mail address with _ (or ._ or _.) isn't invalid, AFAIK.
>
>
> But that wasn't what he asked.
>
> He wanted to filter out three particular email addresses.

Oh please, you know as well as most everyone else those were just
samples. In any case, flagging an email as invalid for having an
underscore ( /_/ ) is plain wrong, and portraying it as a solution is
disingenuous to the OP as well as anyone who comes by this in the
archives.

--
G.Etly


0 new messages