0

I have this piece of code for email verification :

function VerifRegisterEmail(&$email) {

  if(empty($email)) {

    return false;
  }

  $pattern_email = '^[[:alnum:]\.-_]+@[[:alnum:]\.-_]+\.[[:alpha:]]{2, 3}$';
  if(!ereg('^[[:alnum:]\.-_]+@[[:alnum:]\.-_]+\.[[:alpha:]]{2, 3}$', $email)) {
   echo "emaill";
    return false;
  }


  return true;
}

From this i get this error:

Warning: ereg() [function.ereg]: REG_BADBR in C:\Program Files\EasyPHP 2.0b1\www\polydotnet\controler\verif_formulaire.php on line 35
emaill- Email incorrecte

Any clue ?

Thx

Gumbo
  • 643,351
  • 109
  • 780
  • 844
Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158
  • Use preg_match() instead of ereg(), and don't use regex to validate email addresses. – Frank Farmer Jul 16 '09 at 00:42
  • I agree with Frank. If you need to validate an email address, `preg_match('/.+@.+/', $email)` is good enough. – shadowhand Jul 16 '09 at 00:49
  • Why ? Is there a better method for checking email addresses ? – Amokrane Chentir Jul 16 '09 at 00:50
  • 1
    http://mail.python.org/pipermail/python-list/2006-September/404146.html Coders have written thousands of email regexes, and almost all of them fail to conform to RFC 2822. Fully RFC 2822 compliant regexes have been written, mind you -- but they're thousands of characters long. Your regex fails for many simple test cases. – Frank Farmer Jul 16 '09 at 01:02

1 Answers1

1

The space in {2, 3} is causing the problem. Make it {2,3}. Silly, I know.

T .
  • 4,874
  • 3
  • 23
  • 36