As a result of the thread "Check for valid email address", I have modified my emailsyntax() function to better conform to RFC 822. After all, I wouldn't like e.g. my contact form module to reject Randal when he has changed addresses. ;-)

I skipped the specification's "domain-literal" alternative, at least for the time being.

This is the modified function:

    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 $test = 'fred&[EMAIL PROTECTED]';

    print "$test is ", emailsyntax($test) ? 'not ' : '', "ok.\n";

Looking forward to your critique.

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

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to