note 6023 deleted from ref.strings by sander

From: Date: Sun, 07 Apr 2002 13:37:03 +0000
Subject: note 6023 deleted from ref.strings by sander
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-28915@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"; }

« previous php.notes (#28915) next »