Pridit Posted September 13, 2009 Report Share Posted September 13, 2009 (edited) delete Edited July 12, 2010 by Pridit Quote Link to comment Share on other sites More sharing options...
falkencreative Posted September 13, 2009 Report Share Posted September 13, 2009 To be honest, what you say you want the code to do and what the code actually does doesn't seem to match up. According to the PHP manual (http://us2.php.net/manual/en/function.stripos.php) stripos() finds the position of first occurrence of a specified string inside another (case-insensitive) string. So: $emailvalid = stripos($email,"&"); is looking for any instances of the string "&" inside the $email variable. Is that what you want it to do? That doesn't seem to match up with your comment "I'm trying to make the stripos find the email in the variable". In that case, shouldn't it be something more like: $emailvalid = stripos($variable, $email); ?? Also, one other error: This line "if($error = 1)" needs to be "if($error == 1)". Currently, you are setting error to "1" in that line, rather than checking if it equals 1. Quote Link to comment Share on other sites More sharing options...
Pridit Posted September 13, 2009 Author Report Share Posted September 13, 2009 (edited) delete Edited July 12, 2010 by Pridit Quote Link to comment Share on other sites More sharing options...
falkencreative Posted September 13, 2009 Report Share Posted September 13, 2009 Oops, didn't see your edit. Glad you fixed your problem. I will comment that simply searching for "@" isn't necessarily going to be enough to check if there is a valid email address. What if the $_POST value is "sdfasdfasf@sdfsdf"? According to your code, that's a valid address, simply because it includes an "@". (Perhaps you added stronger error checking later, but be aware: NEVER trust any input from a user.) Quote Link to comment Share on other sites More sharing options...
Pridit Posted September 13, 2009 Author Report Share Posted September 13, 2009 (edited) delete Edited July 12, 2010 by Pridit Quote Link to comment Share on other sites More sharing options...
bishwadeep Posted September 17, 2009 Report Share Posted September 17, 2009 Hi you can also validate an email address using regular expressions. if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ echo "Valid Email Address"; }else{ echo "Invalid Email Address"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.