Here is what I use in HyperNews.
sub addressOK {
local ($arg) = @_;
# This is not quite right since it allows "100%."
if ($arg =~ m|^[A-Za-z0-9_=+%/\.\-]+[@%][A-Za-z0-9_\.\-]+$|) {
return $arg;
}
return '';
}
I added the support for '%' (in place of '@'?) after someone said they
needed it. But if is not part of a legal internet address, I'd much
rather remove it.
Ryan Waldron writes:
> sub is_valid_address {
> local ($address) = @_;
>
> # Blanks are bad
> return 0 if (length($address) == 0);
How about whitespace blanks? m/^\s*$/ would catch those.
> # Bogus characters are bad
> return 0 if ( $address =~ m/[^a-zA-Z0-9@%!_.-]/ );
'+' is used sometimes, e.g. p+t@awaken.com
> # C'mon - give us the whole address
> return 0 if ( $address !~ m/.+@.+\..+/ );
Seems to require at least one dot in the domain part. But
liberte@void is legal here within our organization.
What about ^ and $ for beginning and end of string? Otherwise,
other bad junk might be included.
--
Daniel LaLiberte (liberte@ncsa.uiuc.edu)
National Center for Supercomputing Applications
http://union.ncsa.uiuc.edu/~liberte/
Follow-Ups:
References:
|
|