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 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"; } 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. 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
Archived
This topic is now archived and is closed to further replies.