1
$emailPattern = '/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/';

$post_email = strtolower( $_POST[ $field ] );

if( filter_var( $post_email, FILTER_VALIDATE_EMAIL ) )
{ 
    if( preg_match( $email_pattern, $post_email ) )
    { 
        return $post_email;
    }else
    {
        return false;
    }
}else
{
    return false;
}               

Is returning:

Warning: preg_match(): Empty regular expression in /*/functions.php on line

$_POST[ $field ] successfully contains an email address: "something.something@something.uk.com"

What might be going wrong?

Jimmyt1988
  • 20,466
  • 41
  • 133
  • 233
  • [Just use `filter_var()` already.](http://stackoverflow.com/questions/12026842/how-to-validate-an-email-address-in-php/12026863#12026863) – HamZa Jul 31 '13 at 10:43
  • 1
    You need to learn how to [READ and debug](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) error messages. Everything you needed to solve the problem was in the error message. $email_pattern is not set to anything – Anigel Jul 31 '13 at 10:44
  • @Anigel - Sorry to waste your time brah! Me and my silly brain :) – Jimmyt1988 Jul 31 '13 at 10:53
  • NP, it happens to all of us some times. Thats what Second Eye debugging is all about ;) – Anigel Jul 31 '13 at 10:58

1 Answers1

7
preg_match( $email_pattern, $post_email )

should be

preg_match( $emailPattern, $post_email )

Your pattern name variable is $emailPattern and you are using $email_pattern. That is why you are getting warning in preg_match function.

som
  • 4,650
  • 2
  • 21
  • 36