>Would you please share the results with us? I'm dealing with a similar
>problem now, trying to prevent certain characters and strings frm being
>submitted as email addresses, like '#email#' and 'dont'. The code I've used
>just isn't working.


about all you can do with hypothetical email addresses is make sure they're
the right general shape for an RFC822-style address:

    someone@somewhere[.optional].com


this function will give potential addresses a sniff test:


sub is_rfc822 {
    my $data = shift;
    $data = "\L$data";                                  ## 1

    if ($data =~ /</) {                                 ## 2
        $data =~ s/.*<(.*)>.*/$1/;
    }
    my ($name, $machine) = split ('@', $data, 2);       ## 3

    if ($name =~ /[^a-z0-9\-]/) {                       ## 4
        return 0;
    }
    my @domains = split (/\./, $machine);               ## 5

    if (scalar @domains < 2) {                          ## 6
        return 0;
    }
    for $item (@domains) {                              ## 7
        if ($item =~ /[^a-z0-9\-]/) {
            return 0;
        }
    }
    return 1;                                           ## 8
}
#
# 1 - convert to lowercase.. it makes the tests easier.
# 2 - if there are angle brackets, only use what's inside.
# 3 - chop the username away from the machine name.
# 4 - check for bad characters in the name
# 5 - split the machine name to make sure it looks right.
# 6 - if there aren't at least two parts, it's no good.
# 7 - make sure there are no bad characters in the pieces.
# 8 - if we've made it this far, it's the right shape.
#
####

@A = ();
push @A, '[EMAIL PROTECTED]';
push @A, '[EMAIL PROTECTED]';
push @A, '"Kathy E. Gill" <[EMAIL PROTECTED]>';
push @A, '"Dr. Steve" <[EMAIL PROTECTED]>';
push @A, 'Jim Hutchinson <[EMAIL PROTECTED]>';
push @A, '#email#';
push @A, 'you think so..';
push @A, '[EMAIL PROTECTED]';



for $addr (@A) {
    if (&is_rfc822 ($addr)) {
        print "($addr) is good";
    } else {
        print "($addr) is bad";
    }
    print "\n\n";
}









mike stone  <[EMAIL PROTECTED]>




____________________________________________________________________
--------------------------------------------------------------------
 Join The Web Consultants Association :  Register on our web site Now
Web Consultants Web Site : http://just4u.com/webconsultants
If you lose the instructions All subscription/unsubscribing can be done
directly from our website for all our lists.
---------------------------------------------------------------------

Reply via email to