|
|
ru.cgi.perl- RU.CGI.PERL ------------------------------------------------------------------ From : Alexander V. Gaiduk 2:5020/400 05 Mar 2001 18:30:11 To : All Subject : Re: Проверка на валидность мыла --------------------------------------------------------------------------------
у меня такое вроде нормально работает:
честно где то украдено :)
========================
sub checkaddress {
# yeah, yeah, yeah I know that checking for a valid full RFC-822 e-mail
address
# without a parser is a damn pain in the ass.
# _valid_email tries its best, though. :)
# It's gotta be a mailbox. No groups. That's redundant.
# You also have to have a full domain name (and all ultimate top domains
end in
# two or three letters) and _valid_email, unlike the rest of the
validation routines,
# does not return 1 on success, it returns the e-mail address. Why's
that, you ask?
# That way we can use _valid_email to simultaneously extract out the
# actual jim3@psynet.net from "Jim Thomason"<jim3@psynet.net>, for
example.
#
#Set No_errors to 1 if you don't trust it.
my ($email) = @_;
$atom = q<[!#$%&'*+\-/=?^`{|}~\w]>;
$qstring = q/"(?:[^"\\\\\015]|\\\.)+"/;
$word = "($atom+|$qstring)";
$email = _comment_killer($email);
$email =~ m/^$word\s*\<\s*(.+)\s*\>\s*$/; #match beginning phrases
$email = $2 if $2; #if we've got a phrase,
we've extracted
#the e-mail address
#and stuck it in $2, so set
$email to it.
#if we didn't have a
phrase, the whole thing
#is the e-mail address
return $1
if $email =~ m<
^\s*($word # any word (see above)
(?:\.$word)* # optionally followed by a dot,
# and more words, as many times as
we'd like
@ # and an at symbol
$atom+ # followed by as many atoms as we
want
(?:\.$atom+)* # optionally followed by a dot, and
more
# atoms, as many times as we'd like
\.[a-zA-Z]{2,3})\s*$ # followed by 2 or 3 letters, and
# an optional greater than
>xo;
};
sub _comment_killer {
my ($email) = shift;
while ($email =~ /\((?:[^()\\\015]|\\.)*\)/){$email =~
s/\((?:[^()\\\015]|\\.)*\)//};
return $email;
};
========================
--- ifmail v.2.15dev5
* Origin: Demos online service (2:5020/400)
Вернуться к списку тем, сортированных по: возрастание даты уменьшение даты тема автор
Архивное /ru.cgi.perl/3931e1917eca.html, оценка из 5, голосов 10
|