note 38272 added to function.ereg
| From: | thehiddenfire at yahoo dot com | Date: | Sun, 14 Dec 2003 23:42:34 +0000 |
| Subject: | note 38272 added to function.ereg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61957@lists.php.net to get a copy of this message | ||
I've developed this function for use in both PHP and javascript. It checks for the validity of
the syntax of an email address and allows multiple subdomains and use of periods (.), hypens (-) and
underscores (_) in throughout the entire string. The only things it doesn't check for is valid
IP address in the domain section of the email address which could very well be possible (e.g.:
email@127.0.0.1).
function email_syntax($addr) {
$exp = "^[A-Za-z0-9_][A-Za-z0-9\.{0,1}\-{0,1}_]*[A-Za-z0-9]@" . // name@
"[A-Za-z0-9_][A-Za-z0-9\.{0,1}\-{0,1}_]*[A-Za-z0-9]\." . //
(sub)domain(s)
"[A-Za-z0-9_]([A-Za-z0-9\.{0,1}\-{0,1}])*[A-Za-z0-9]*$"; // domain.tld
(top level domain)
return ereg($exp, $addr);
}
(code may wrap, sorry)
http://gha.kicks-ass.org
----
Manual Page -- http://www.php.net/manual/en/function.ereg.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38272
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38272&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38272&report=yes
Search -- http://master.php.net/manage/user-notes.php