boionfire81 Posted July 6, 2016 Share Posted July 6, 2016 Ok, here is the code after changing the ereg to preg_match function valid_email($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!preg_match("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!preg_match("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|("[^(\\|")]{0,62}"))$", $local_array[$i])) { return false; } } if (!preg_match("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!preg_match("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } This is for one of my new mod purchases. phpcodecheck return no issues found. But when the form is submitted it returns: A critical error has occurred, and page execution has stopped. Below are the details: PHP Warning: preg_match(): Unknown modifier '@' (2) Quote Link to comment Share on other sites More sharing options...
IllegalPigeon Posted July 6, 2016 Share Posted July 6, 2016 (edited) Well, the regular expressions used there are a bit silly anyway. You need to add delimiters to the expression, making the expression; /^[^@]{1,64}@[^@]{1,255}$/ But the more sensible solution would be to use filter_var(). if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { return false; } Also, quick edit. The source code for FILTER_VALIDATE_EMAIL does a much more comprehensive check on the email. Source. Edited July 6, 2016 by IllegalPigeon Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted July 7, 2016 Share Posted July 7, 2016 (edited) goto agree with ip on this one filter validate email is much better Edited July 7, 2016 by NonStopCoding spelling oops ;) 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.