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.



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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...