wut Posted April 18, 2012 Share Posted April 18, 2012 im looking to validate an email address before it gets sent to mysql database currently my code checks if an email address is present and if an email address already exists how do you check to see if an address contains a . and a @ symbol? if($email == '') { $errmsg_arr[] = 'Email is missing'; $errflag = true; } if($email != '') { $qry = "SELECT * FROM users WHERE email='$email'"; $result = mysql_query($qry); if($result) { if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'Email address already in use'; $errflag = true; } @mysql_free_result($result); } else { die("Query failed"); } } Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/261195-validation/ Share on other sites More sharing options...
plznty Posted April 18, 2012 Share Posted April 18, 2012 strpos - http://php.net/manual/en/function.strpos.php Quote Link to comment https://forums.phpfreaks.com/topic/261195-validation/#findComment-1338544 Share on other sites More sharing options...
batwimp Posted April 18, 2012 Share Posted April 18, 2012 You may also want to check into this: http://us3.php.net/manual/en/filter.filters.validate.php Though some say it has some problems. Read the comments. Quote Link to comment https://forums.phpfreaks.com/topic/261195-validation/#findComment-1338546 Share on other sites More sharing options...
wut Posted April 18, 2012 Author Share Posted April 18, 2012 if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ $errmsg_arr[] = 'Email is not valid'; $errflag = true; } This seems to have done the trick nicely! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/261195-validation/#findComment-1338549 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.