Jump to content
Larry Ullman's Book Forums

Recommended Posts

I've been using a script to check submissions for proper email formatting. It looks like this:

 

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

 

Note, that I didn't write this script, it was provided by someone else.

 

It's worked fine for years, but now I'm getting an error message saying the function has been deprecated. I think my host must have installed a new version of PHP, 5.3.2.

 

That's cool, I just need to figure out what to replace this code with. I've done a little research and it seems there are several ways to approach this, including:

 

1. just replace "eregi" with "preg_match."

2. use "filter_var" and "FILTER_VALIDATE_EMAIL" instead.

 

Any advice as to what would be the best way to update this script would be greatly appreciated.

 

Thanks!

Link to comment
Share on other sites

Thanks, Larry. I'm going to give that a try. Out of curiosity, do you know exactly what the filter "filters?" I looked around on the web and couldn't find any specific information about this. I found that as long as I entered anything with an @ in it it worked. I thought it would also require some sort of .com/.net, etc. at the end, but it doesn't seem to. For example:

 

swilkison (this triggers an error)

swilkison@comcast (this works fine, even though there is no .net at the end)

Link to comment
Share on other sites

 Share

×
×
  • Create New...