-5

Possible Duplicate:
Function eregi() is deprecated

I have created a contact form with PHP, but am getting a warning:

Deprecated: Function eregi() is deprecated in D:\hosting\9606426\html\Websites\LuxeBeauty\1\contact.php on line 9

This is line 9:

if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-
z]{2,}"."$",$email )){
    ...
}

What should I do to fix this?

Community
  • 1
  • 1
Henry Aspden
  • 1,863
  • 3
  • 23
  • 45
  • What have you tried? Dumping all your code here means _"Debug this for me"_, which is not the way things work here. Try searching the web on the warning you get and see which methods are recommended. – CodeCaster Oct 17 '12 at 09:16
  • 2
    Perhaps RTFM? It's all explained here: http://php.net/eregi – Oldskool Oct 17 '12 at 09:16
  • use preg instead, just like it says in the manual. Or use the filtering functionality – GordonM Oct 17 '12 at 09:17

1 Answers1

5

eregi has been depreciated, which means that you'll need to switch to:

if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
    $error.="Invalid email address entered";
    $errors=1;
}
Wayne Whitty
  • 19,513
  • 7
  • 44
  • 66
  • 3
    +1 for not using a regex for email validation. – CodeCaster Oct 17 '12 at 09:16
  • 1
    @CodeCaster I tried my best to get this in before the wave of preg_match examples! – Wayne Whitty Oct 17 '12 at 09:18
  • to me the original code I pasted seems far too complicated. I usually don't bother with echoing text, instead just send to a URL, one saying success, other saying OOps (or something like that). But this particular client asked for it to come up there and then... – Henry Aspden Oct 17 '12 at 09:27
  • As its a template, i have little clue what parts of the full PHP do... Looking at line 9, am I right that all it does is check that an email address is valid? I.E. has an @ sign in it, and only certain characters? – Henry Aspden Oct 17 '12 at 09:29
  • OOH and that did the trick perfectly... Sorry for my ignorance, I don't use this site much, only now an then for weird bugs. I am an IT Consultant usually with network systems etc, not a designer and not a developer usually haha... Thanks for all your help tho. ^^ Question above still stands though... ^^^ – Henry Aspden Oct 17 '12 at 09:32
  • As of PHP 5.3.3, FILTER_VALIDATE_EMAIL is based on this blog post by Michael Rushton: http://squiloople.com/2009/12/20/email-address-validation/ – Wayne Whitty Oct 17 '12 at 09:33