Click here to get back home

Email address syntax check?

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    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
Email address syntax check? tuxedo 12-02-2006
Posted by tuxedo on December 2, 2006, 2:58 pm
Please log in for more thread options


I'd like to do a email address verification as part of a simple cgi web mail
submission form. I'm considering use of the Email::Valid module, which
requires Mail::Address, which is part of the MailTools-1.74 package.

However, unfortunately, I do not have sufficient permissions to install
modules other than in external directories on the server.

The Email::Valid module is not a problem as it can be installed by ...

perl Makefile.PL PREFIX=/where/I/want/it/put

... but the installation of MailTools-1.74 does not offer the same
possibility through the PREFIX method. I tried but I got the usual error:
"Warning: You do not permission to install in /usr/lib/perl5/.." etc.

Anyone happens to know a solution? Or perhaps better, a procedure that is
already part of the perl version which I have - perl 5.6.1.

What I'm hoping for is a non-critical address syntax check, without getting
my hands dirty with complex regex's and RFC's....

Any pointers to man pages, or even entire syntax checking code, would be
greatly appreciated!

Many thanks!


Posted by tuxedo on December 2, 2006, 3:33 pm
Please log in for more thread options


I wrote:

[...]

> Any pointers to man pages, or even entire syntax checking code, would be
> greatly appreciated!

To be a bit more specific in terms of the conditions I would like to check
and what I consider valid form input, that is: one or more comma or white
space separated valid email addresses.

What I do not need or plan to make use of are live checks that query smtp
servers for existence of addresses, as I understand such type of procedures
do not necessarily work, nor could they speed up the cgi processing.


Posted by Gunnar Hjalmarsson on December 2, 2006, 3:34 pm
Please log in for more thread options


tuxedo wrote:
> I'd like to do a email address verification as part of a simple cgi web mail
> submission form.

I'm using this sub in a couple of applications:

sub emailsyntax {
return 1 unless my ($localpart, $domain) = shift =~ /^(.+)@(.+)/;
my $atom = '[^[:cntrl:] "(),.:;<>@\[\\]]+';
my $qstring = '"(?:\.|[^"\\s]|[ \t])*"';
my $word = qr($atom|$qstring);
return 1 unless $localpart =~ /^$word(?:\.$word)*$/;
$domain =~ /^$atom(?:\.$atom)+$/ ? 0 : 1;
}

my $address = 'john.smith@example.com';
print "Syntax ok\n" unless emailsyntax($address);

It's not as strict as RFC 822; for instance it accepts non-ASCII
characters. Still catches most syntactical typos.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Posted by tuxedo on December 2, 2006, 4:07 pm
Please log in for more thread options


Gunnar Hjalmarsson wrote:

[...]

> It's not as strict as RFC 822; for instance it accepts non-ASCII
> characters. Still catches most syntactical typos.

Many thanks for this contribution - I will test and hopefully it will fit my
purpose perfectly!

Posted by Gunnar Hjalmarsson on December 2, 2006, 4:16 pm
Please log in for more thread options


tuxedo wrote:
> Gunnar Hjalmarsson wrote:
>>It's not as strict as RFC 822; for instance it accepts non-ASCII
>>characters. Still catches most syntactical typos.
>
> Many thanks for this contribution

You're welcome.

> - I will test and hopefully it will fit my purpose perfectly!

Please let me know of possible findings.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Similar ThreadsPosted
Looking for module that will expands domain/username to email address October 23, 2004, 12:56 am
Ip address Data Type DBI May 10, 2006, 4:38 pm
Can't find Module IP::Address February 27, 2008, 3:42 pm
IPV6 socket connection, with a link-local address January 11, 2008, 1:12 pm
Help with XML::Twig xpath syntax, please October 16, 2005, 6:56 pm
SVN::Agent check out? August 10, 2008, 4:52 pm
Net::SFTP ssh_args=>[ ] syntax question... August 19, 2004, 9:48 am
Class::MethodMaker v2 syntax help requested February 7, 2005, 9:33 pm
Pod syntax and hyperlinks to =item entries December 8, 2005, 8:37 pm
check response with mod_perl October 22, 2004, 11:23 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap