0

Here is my code (from submit.php) that is throwing an error:

$email_from = $_POST['email']; // required
$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
if(!eregi($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}

I know I need to use preg_match, but I don't know how to implement it. I've read the documentation, but I still don't get it. Thanks!

Charles L
  • 63
  • 1
  • 1
  • 6
  • 1
    Take a look at this question: http://stackoverflow.com/questions/6270004/how-can-i-convert-ereg-expressions-to-preg-in-php – MrHunter Feb 05 '14 at 12:40
  • Perl regexps and POSIX regexps are very very similar to eachother. This one would work as a perl regexp automatically; no need to change anything within it. However, since you really want it to be case-INsensitive, you either have to add the i modifier at the end, or replace all A-Z with A-Za-z (ie. both cases). – Tularis Feb 05 '14 at 12:43

2 Answers2

-1

remove this

  $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  eregi($email_exp,$email_from) 

and use

$email_exp = "/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i";
preg_match($email_exp, $email_from)
krishna
  • 4,069
  • 2
  • 29
  • 56
-1
$email_exp = "/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i";
 if(preg_match($email_exp,$email_from) != 1) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}

Actually, it'is very simple and very similar with eregi.

Halil Bilgin
  • 513
  • 4
  • 14