note 6023 modified in String functions by ronabop
| From: | ronabop@php.net | Date: | Fri, 11 Aug 2000 17:02:01 +0000 |
| Subject: | note 6023 modified in String functions by ronabop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-1310@lists.php.net to get a copy of this message | ||
I have a function to check for email, probably could be a lot more efficient using regular
expressions or something but I'm not sure how to do that. This works, anyhow.<br>
// check for stuff around @
$pos = strpos ($fEmail, "@");
if (($pos == 0) or ($pos == strlen($fEmail) - 1)) {
echo "Invalid email";
} else {
// check for a @ after the first @
$pos = strpos ($fEmail, "@", strpos ($fEmail, "@")+1);
if ($pos != false) {
echo "Invalid email";
}
}
Note that this does not check for a . after the @ sign, allowing for "user@workgroup" or
something in an intranet setting.
To do that, just add:
if (!strpos ($fEmail, ".", strpos ($fEmail, "@")+1)) {
echo "Invalid email";
}
http://www.php.net/manual/string-functions.php