note 53677 added to function.preg-match
| From: | sunil_ssm at users dot sourceforge dot net | Date: | Thu, 09 Jun 2005 02:06:32 +0000 |
| Subject: | note 53677 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90146@lists.php.net to get a copy of this message | ||
The following function validates an email address. Does a better job than most validate functions
and with very minimal coding.
------------
function is_email($addr)
{
//Check for illegal sequences.
//Note: I had to expand the variable '$illegal' to 2 DIFFERENT lines to allow this post.
//php.net complains that this line is too long !!!
$illegal = "/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|";
$illegal .= "(\.$)|(^\_)|(\_@)|(\-\-)|(\_\_)/";
//Check for proper format.
$format = "/^([a-z0-9\\_\\.]+)@[a-z0-9\\-\\.]+\\.([a-z]+)$/i";
if(!preg_match($illegal, $addr) && preg_match($format,$addr)) return true;
return false;
}
------------
Sunil Amber
http://jformmail.sourceforge.net/
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+53677
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53677&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53677&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53677&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53677&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53677&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53677&report=yes
Search -- http://master.php.net/manage/user-notes.php