-1

Deprecated code:

function validate_email($email)
{
    return eregi("^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$", $email);
}

I am a JavaScript beginner. The above code gives an error. I am not too sure how to rewrite using preg_match.

The Alpha
  • 143,660
  • 29
  • 287
  • 307
sam
  • 1
  • Make sure you add regex delimiters with `preg_match` and it should work. But also `filter_var($email, FILTER_VALIDATE_EMAIL)` – elclanrs Sep 14 '13 at 23:33

1 Answers1

0

Try this instead

function validate_email($email)
{
    return (1 === preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email));
}

preg_match() should be used rather than eregi. You must include the slashes at the begining and end of the pattern. And finally, the "/i" at the end of the pattern makes it case-insensitive.

crempp
  • 248
  • 1
  • 7