Home: Perl Programming Help: Regular Expressions:
can any one tell how to validate correct email address using perl script



aniket
New User

Dec 10, 2009, 6:17 AM


Views: 7967
can any one tell how to validate correct email address using perl script

Can any one tell how to Write a program in perl with the following aim:

- takes an email address as input

- outputs a "valid" or "invalid" - valid if the email address is

valid, and invalid if it is invalid.

- make your own assumptions about what is a valid email addres and what is invalid.

I tried below stuff but didnt worked..please help me:

#!/usr/bin/perl -w

print ("Please type yor email id:\n");

$email = <STDIN>;

if ($email =~ /^(\w\-\_\.)+\@((\w\-\_)+\.)+[a-zA-Z]{2,}$/)

{

print ("$email is valid");

}

else {

print ("$email is invalid");

}





Please help me.


(This post was edited by aniket on Dec 10, 2009, 6:37 AM)


shawnhcorey
Enthusiast


Dec 10, 2009, 6:53 AM


Views: 7960
Re: [aniket] can any one tell how to validate correct email address using perl script

Entering `email validation` in CPAN search gives 203 responses.

http://search.cpan.org/search?query=email+validation&mode=all

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


aniket
New User

Dec 10, 2009, 8:12 AM


Views: 7949
Re: [shawnhcorey] can any one tell how to validate correct email address using perl script

Shawn,

thank for your reply i was trying below code:

#!/usr/bin/perl -w

use Data::Validate::Email qw(is_email is_email_rfc822);

$emailid=<stdin>;

if(is_email($emailid))
{
print "Looks like an email address\n";
}
elsif(is_email_rfc822($emailid))
{
print ("Doesn't much look like an email address, but passes rfc822\n");
}
else

{
print ("Not an email address\n");

}

but some how i dont have this email.Pm ...How can i get that ?