Morris2 Posted October 20, 2011 Share Posted October 20, 2011 Hi. A quick one: How do I write this in PHP? if (this variable don't contain "@") echo "This is not a valid email address"; Regards Morris Quote Link to comment https://forums.phpfreaks.com/topic/249440-how-do-i-write-this-in-php-if-this-variable-dont-contain/ Share on other sites More sharing options...
Drummin Posted October 20, 2011 Share Posted October 20, 2011 if (!preg_match('/[@]/', $email)){ echo "This is not a valid email address"; } You can also use a built in fuction if(filter_var($email, FILTER_VALIDATE_EMAIL)){ echo "Email is good"; }else{ echo "This is not a valid email address"; } Quote Link to comment https://forums.phpfreaks.com/topic/249440-how-do-i-write-this-in-php-if-this-variable-dont-contain/#findComment-1280761 Share on other sites More sharing options...
JonnoTheDev Posted October 20, 2011 Share Posted October 20, 2011 if (!preg_match('/[@]/', $email)){ } Poor test for an email address. Is ne@il an email address? No. The second example provided by Drummin is much better. Quote Link to comment https://forums.phpfreaks.com/topic/249440-how-do-i-write-this-in-php-if-this-variable-dont-contain/#findComment-1280806 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.