Search code examples
phpregexposix-ere

PHP - REG_BADBR error when using ereg() for regexp


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


Solution

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