-1

Possible Duplicate:
Converting ereg expressions to preg

I need to convert the ereg usage here to something more current (since ereg is deprecated).

Here's the function my code currently relies on:

function ValidEmail($address)
{
    if( ereg( ".*<(.+)>", $address, $regs ) ) {
        $address = $regs[1];
    }

    if(ereg( "^[^@  ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$",$address) ) 
        return true;
    else
        return false;
}

As I don't regex - could someone help me convert the function to something that functions the exact same way but isn't using a deprecated function? Thanks.

Community
  • 1
  • 1
doremi
  • 14,921
  • 30
  • 93
  • 148
  • Change `ereg` to `preg_match` and check the syntax and options at http://au.php.net/manual/en/function.preg-match.php – pavium Jun 18 '11 at 02:48
  • Without knowing regex, I have no idea how to safely convert the regex to something that is preg_match friendly. Simply replacing ereg with preg_match doesn't work - I'm getting unknown modifier errors. – doremi Jun 18 '11 at 02:57

1 Answers1

1

Looks like all I needed to add was switch ereg to preg_match and add a delimiting character to each pattern:

function ValidEmail($address)
{
    if( preg_match( "/.*<(.+)>/", $address, $regs ) ) {
        $address = $regs[1];
    }

    if(preg_match( "/^[^@  ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$/",$address) ) 
        return true;
    else
        return false;
}
doremi
  • 14,921
  • 30
  • 93
  • 148