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

Email address syntax check?

0 views
Skip to first unread message

tuxedo

unread,
Dec 2, 2006, 2:58:00 PM12/2/06
to
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!

tuxedo

unread,
Dec 2, 2006, 3:33:46 PM12/2/06
to
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.

Gunnar Hjalmarsson

unread,
Dec 2, 2006, 3:34:47 PM12/2/06
to
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....@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

Chris Davies

unread,
Dec 2, 2006, 3:36:13 PM12/2/06
to
tuxedo <tux...@mailinator.com> wrote:
> 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.

Recheck the FAQ on this, which refers to LIB as well as PREFIX.

Regards,
Chris

tuxedo

unread,
Dec 2, 2006, 4:07:43 PM12/2/06
to
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!

Gunnar Hjalmarsson

unread,
Dec 2, 2006, 4:16:57 PM12/2/06
to
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.

tuxedo

unread,
Dec 2, 2006, 4:59:02 PM12/2/06
to
Gunnar Hjalmarsson wrote:

> Please let me know of possible findings.

Thanks. But I can't quite see through this. I get a perl syntax error
near "=~ ^".

Any chance that you could kindly post your complete script within a
cut-n-paste example for the blind and stupid?

Many thanks!

Gunnar Hjalmarsson

unread,
Dec 2, 2006, 5:17:24 PM12/2/06
to

But... The code I posted _is_ intended to copy, paste and run. Your
newsreader must have done something with it.

Try to copy from:
http://groups.google.com/group/comp.lang.perl.modules/msg/e7e65ccea8c2fac9

tuxedo

unread,
Dec 2, 2006, 5:38:01 PM12/2/06
to
Gunnar Hjalmarsson wrote:

[..]

> newsreader must have done something with it.

Yes - some of the forward slashes were gone. Damn newsreader! If I view
source they are all there and your script works fine - thanks again!

0 new messages